diff options
author | Matthew Draper <matthew@trebex.net> | 2017-04-12 22:39:15 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2017-04-12 23:38:57 +0930 |
commit | 7384771dd0652ec4d82c0ad16522a87102316aee (patch) | |
tree | bf2fbbe92b154f4cca7a2a70abd6eb2d6d496e5e /activerecord/lib/active_record/connection_adapters | |
parent | 2b4583f2a2ef94bc8c046e36e2b62ec642bbfb41 (diff) | |
download | rails-7384771dd0652ec4d82c0ad16522a87102316aee.tar.gz rails-7384771dd0652ec4d82c0ad16522a87102316aee.tar.bz2 rails-7384771dd0652ec4d82c0ad16522a87102316aee.zip |
Use a query that's compatible with PostgreSQL 9.2
Also, explicitly apply the order: generate_subscripts is unlikely to
start returning values out of order, but we should still be clear about
what we want.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 1d439acb07..02a6da2f71 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -344,13 +344,17 @@ module ActiveRecord def primary_keys(table_name) # :nodoc: select_values(<<-SQL.strip_heredoc, "SCHEMA") - SELECT a.attname FROM pg_index i - CROSS JOIN generate_subscripts(i.indkey, 1) k - JOIN pg_attribute a - ON a.attrelid = i.indrelid - AND a.attnum = i.indkey[k] - WHERE i.indrelid = #{quote(quote_table_name(table_name))}::regclass - AND i.indisprimary + SELECT a.attname + FROM ( + SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx + FROM pg_index + WHERE indrelid = #{quote(quote_table_name(table_name))}::regclass + AND indisprimary + ) i + JOIN pg_attribute a + ON a.attrelid = i.indrelid + AND a.attnum = i.indkey[i.idx] + ORDER BY i.idx SQL end |