From: David Kerr Date: 2012-03-23T03:22:40+09:00 Subject: ActiveRecord and working with sequences Howdy, (sorry if this ends up as a duplicate post, my subscription was messed up) I'm very new with ruby and ActiveRecord. I've got a table in postgres that looks something like create table test test_id not null default nextval('test_id_seq') test_parent int not null test_name varchar(20) not null For the parent record, test_parent = test_id. I can't change the schema, so i need to work with the table structure I have. What's the best way to handle that situation in ActiveRecord? It seems like i should do something like: SEQ = Test.new(:test_id => SEQ, :test_parent => SEQ, :test_name => 'woohoo' ); I'm not sure how to active the portion with ActiveRecord. I tried: seq = ActiveRecord::Base.connection.execute("SELECTnextval('test_id_seq')") And that seems to be doable, but the PG:Result class is a little weird, so I was hoping there was a better way. Thanks. Dave