This project is archived and is in readonly mode.

#3604 ✓stale
Jade Rubick

Postgres adapter does not honor set_sequence_name

Reported by Jade Rubick | December 21st, 2009 @ 03:56 PM

I am using a legacy database that uses one sequence for all the tables in the system. There does not seem to be a way to support this in Rails using Postgres.

I read in various places that you could use set_sequence_name is your Rails models:

class ForumsForum < ActiveRecord::Base
set_primary_key :forum_id
set_sequence_name 't_acs_object_id_seq'
... end

However, Rails seems to completely ignore this directive for Postgres. I think it does work for Oracle, but it really does not seem to for Postgres.

Here's a unit test:

def test_save_message
forum = ForumsForum.new(:name => 'Test forum', <br/> :charter => 'Test charter', \ :presentation_type => 'abc', \ :posting_policy => 'abc', \ :enabled_p => 'f') forum.save
... end

Here's the result of the test:

1) Error:
test_save_message(ForumsMessageTest):
ActiveRecord::StatementInvalid: PGError: ERROR: null value in column "forum_id" violates not-null constraint
: INSERT INTO "forums_forums" ("name", "package_id", "last_post", "thread_count", "approved_thread_count", "max_child_sortkey", "charter", "posting_policy", "presentation_type", "enabled_p") VALUES(E'Test forum', NULL, NULL, 0, 0, NULL, E'Test charter', E'abc', E'abc', E'f') RETURNING "forum_id" test/unit/forums_message_test.rb:20:in test_save_message'

1 tests, 0 assertions, 0 failures, 1 errors

Note the RETURNING statement. All variations I tried to set_sequence_name did not work. After a little looking, I saw this:

http://www.ruby-forum.com/topic/81873

And looking into the Rails source code, at first glance it does appear that the sequence name is not honored.

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar October 8th, 2010 @ 12:30 PM

    • State changed from “new” to “stale”
    • Importance changed from “” to “Low”

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages