diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-12-08 04:34:26 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-12-08 04:34:26 +0000 |
commit | c1537e89f89d1460e3b0fb0dc87d2a310afa3cbc (patch) | |
tree | f6893f14b291e08f2f1a93aa0e00dffcf4db9d1b /activerecord/lib | |
parent | bae97ef4830e128826c215298d6d92a97ff1e136 (diff) | |
download | rails-c1537e89f89d1460e3b0fb0dc87d2a310afa3cbc.tar.gz rails-c1537e89f89d1460e3b0fb0dc87d2a310afa3cbc.tar.bz2 rails-c1537e89f89d1460e3b0fb0dc87d2a310afa3cbc.zip |
PostgreSQL: more robust sequence name discovery. References #3087.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3235 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 8619da8c5b..8f2ba6e6c4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -251,7 +251,7 @@ module ActiveRecord # First try looking for a sequence with a dependency on the # given table's primary key. result = execute(<<-end_sql, 'PK and serial sequence')[0] - SELECT attr.attname, (name.nspname || '.' || seq.relname) + SELECT attr.attname, name.nspname, seq.relname FROM pg_class seq, pg_attribute attr, pg_depend dep, @@ -274,7 +274,7 @@ module ActiveRecord # the 8.1+ nextval('foo'::regclass). # TODO: assumes sequence is in same schema as table. result = execute(<<-end_sql, 'PK and custom sequence')[0] - SELECT attr.attname, (name.nspname || '.' || split_part(def.adsrc, '\\\'', 2)) + SELECT attr.attname, name.nspname, split_part(def.adsrc, '\\\'', 2) FROM pg_class t JOIN pg_namespace name ON (t.relnamespace = name.oid) JOIN pg_attribute attr ON (t.oid = attrelid) @@ -285,7 +285,8 @@ module ActiveRecord AND def.adsrc ~* 'nextval' end_sql end - result + # check for existence of . in sequence name as in public.foo_sequence. if it does not exist, join the current namespace + result.last['.'] ? [result.first, result.last] : [result.first, "#{result[1]}.#{result[2]}"] rescue nil end |