diff options
author | Matthew Draper <matthew@trebex.net> | 2017-04-13 01:51:52 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-13 01:51:52 +0930 |
commit | 0eb21874cb89dc5ca42945111b4e4ae94106b3e5 (patch) | |
tree | bf2fbbe92b154f4cca7a2a70abd6eb2d6d496e5e /activerecord/lib/active_record | |
parent | 2b4583f2a2ef94bc8c046e36e2b62ec642bbfb41 (diff) | |
parent | 7384771dd0652ec4d82c0ad16522a87102316aee (diff) | |
download | rails-0eb21874cb89dc5ca42945111b4e4ae94106b3e5.tar.gz rails-0eb21874cb89dc5ca42945111b4e4ae94106b3e5.tar.bz2 rails-0eb21874cb89dc5ca42945111b4e4ae94106b3e5.zip |
Merge pull request #28740 from matthewd/old-postgres
Use a query that's compatible with PostgreSQL 9.2
Diffstat (limited to 'activerecord/lib/active_record')
-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 |