diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-03-19 19:10:07 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-03-20 18:48:34 +0900 |
commit | dbd2fc8907e7fa4756ea26c5c52334cd4baefd2b (patch) | |
tree | e876f64710095752cfa37399b1a44cdc56e9372a /activerecord/lib | |
parent | 1835d87fb848fd9f13e43bf16abd41be231b1666 (diff) | |
download | rails-dbd2fc8907e7fa4756ea26c5c52334cd4baefd2b.tar.gz rails-dbd2fc8907e7fa4756ea26c5c52334cd4baefd2b.tar.bz2 rails-dbd2fc8907e7fa4756ea26c5c52334cd4baefd2b.zip |
Fix `primary_keys` across multiple schemas
Fixes #28470.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 16 |
1 files changed, 7 insertions, 9 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 a332375b78..2927a76385 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -362,16 +362,14 @@ module ActiveRecord end def primary_keys(table_name) # :nodoc: - scope = quoted_scope(table_name) select_values(<<-SQL.strip_heredoc, "SCHEMA") - SELECT column_name - FROM information_schema.key_column_usage kcu - JOIN information_schema.table_constraints tc - USING (table_schema, table_name, constraint_name) - WHERE constraint_type = 'PRIMARY KEY' - AND kcu.table_name = #{scope[:name]} - AND kcu.table_schema = #{scope[:schema]} - ORDER BY kcu.ordinal_position + 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 SQL end |