method

primary_keys

Importance_0
v5.0.0.1 - Show latest stable - 0 notes - Class: SchemaStatements
primary_keys(table_name) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 433
        def primary_keys(table_name) # :nodoc:
          select_values(            WITH pk_constraint AS (              SELECT conrelid, unnest(conkey) AS connum FROM pg_constraint              WHERE contype = 'p'                AND conrelid = '#{quote_table_name(table_name)}'::regclass            ), cons AS (              SELECT conrelid, connum, row_number() OVER() AS rownum FROM pk_constraint            )            SELECT attr.attname FROM pg_attribute attr            INNER JOIN cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.connum            ORDER BY cons.rownum.strip_heredoc, 'SCHEMA')
        end
Register or log in to add new notes.