Module: Atchu::Queries
Instance Method Summary collapse
Instance Method Details
#primary_key(table_name) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/atchu/queries.rb', line 5 def primary_key table_name sql = <<-SQL SELECT pg_attribute.attname FROM pg_index, pg_class, pg_attribute WHERE pg_class.oid = '#{table_name}'::regclass AND indrelid = pg_class.oid AND pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = any(pg_index.indkey) AND indisprimary SQL end |