Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:00:56+00:00 2026-06-09T22:00:56+00:00

I have a table in a legacy database that has a column named field.

  • 0

I have a table in a legacy database that has a column named field.
It is impossible to link the table directly to an activeRecord model, since the latter will try to create the method field_changed? which is already defined.

So I created a view to rename the field and created the following rules to allow inserts, updates and deletes.

create or replace rule new_linked_fields_upd as on update to new_linked_fields 
     do instead 
     update linked_fields set race_id = new.race_id , master_id = new.master_id, field = new.field_name
     where id = new.id;

create or replace rule new_linked_fields_ins as on insert to new_linked_fields
     do instead
     insert into linked_fields select nextval('linked_fields_id_seq'), new.race_id, new.field_name, new.master_id;

create or replace rule new_linked_fields_del as on delete to new_linked_fields
     do instead
      delete from linked_fields where id = old.id;

I linked the activeRecord model to the view.

class LinkedField < ActiveRecord::Base
  self.table_name ="new_linked_fields"
  self.primary_key = "id"
end

I had to add self.primary_key = “id”, otherwise, methods such as LinkedField.last would fail (generating bad SQL).

In SQL everything works great.
In ruby, I can update the attributes of a LinkedField, or destroy an instance, but I can’t create one.

LinkedField.create(field_name:'toto',race_id:-3,master_id:4)

Returns the following error.

   (0.3ms)  BEGIN
  SQL (1.0ms)  INSERT INTO "new_linked_fields" ("field_name", "master_id", "race_id") VALUES ($1, $2, $3) RETURNING "id"  [["field_name", "toto"], ["master_id", 4], ["race_id", -3]]
   (0.3ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::Error: ERROR:  syntax error at end of input
LINE 1: DEALLOCATE
                   ^
: INSERT INTO "new_linked_fields" ("field_name", "master_id", "race_id") VALUES ($1, $2, $3) RETURNING "id"
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:297:in `exec'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:297:in `dealloc'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:287:in `delete'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1172:in `rescue in exec_cache'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1155:in `exec_cache'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:665:in `block in exec_query'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/relation.rb:66:in `insert'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/persistence.rb:363:in `create'
     from /Users/macbook/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.6/lib/active_record/timestamp.rb:57:in `create'

Any cue? I’m using postgres 9.0 and rails 3.2.6.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:00:58+00:00Added an answer on June 9, 2026 at 10:00 pm

    First, if you’re able to update to PostgreSQL 9.1, view triggers are way easier to get right than rules.

    Second, where is DEALLOCATE coming from? Is it trying to free a prepared statement?

    Try enabling log_statement = 'all' in postgresql.conf, reloading PostgreSQL (pg_ctl reload, SIGHUP the postmaster, or restart it), re-run your test and examine Pg’s logs. See what SQL your Rails program is actually running.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy SQL Server 2000 database that has one column that has
I have a legacy SQL database that has a linked table to store specifications
I have a table that contains the stock. It's legacy database and the stock
I have a table which has essentially boolean values in a legacy database. The
I am working with a legacy database that has a table to store up
Im working on a legacy database, that cant be changed. I have a table
I have a table message in a database that has almost a million rows.
I have a 'legacy' DB2 database that has many other applications and users. Trying
I have a table that has column names similar to ADDRESS, OLD_ADDRESS, CITY, OLD_CITY,
I have a legacy mysql database and there's this table which has a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.