list all foreign keys for a table postgres

Solutions on MaxInterview for list all foreign keys for a table postgres by the best coders in the world

showing results for - "list all foreign keys for a table postgres"
Yannic
11 Apr 2019
1select kcu.table_schema || '.' ||kcu.table_name as foreign_table,
2       '>-' as rel,
3       rel_tco.table_schema || '.' || rel_tco.table_name as primary_table,
4       string_agg(kcu.column_name, ', ') as fk_columns,
5       kcu.constraint_name
6from information_schema.table_constraints tco
7join information_schema.key_column_usage kcu
8          on tco.constraint_schema = kcu.constraint_schema
9          and tco.constraint_name = kcu.constraint_name
10join information_schema.referential_constraints rco
11          on tco.constraint_schema = rco.constraint_schema
12          and tco.constraint_name = rco.constraint_name
13join information_schema.table_constraints rel_tco
14          on rco.unique_constraint_schema = rel_tco.constraint_schema
15          and rco.unique_constraint_name = rel_tco.constraint_name
16where tco.constraint_type = 'FOREIGN KEY'
17group by kcu.table_schema,
18         kcu.table_name,
19         rel_tco.table_name,
20         rel_tco.table_schema,
21         kcu.constraint_name
22order by kcu.table_schema,
23         kcu.table_name;
queries leading to this page
get foreign keys for a table postgrespostgresql how to find all tables that refer to one as foreign keypsql create table with list of foreign keypsql list table foreign keysfind all foreign keys postgresselect foreign key postgrespostgres get foreign key constraint namepostgres list foreign keyspsql list foreign keysforeign keys list psqlforeign key postgresql listget all foreign keys postgresqllist all foreign keys for a table postgresconstraint to get all related foreingkey in postgreepostgres get foreign key constrainshow foreign key postgresql in tablepostgresql foreign key get all tablehow to check foreign keys in table postgresqllist foreign key constraint postgresshow foreign key postgresshow foreign keys on table postgresfind foreign key postgrespostgres foreign key list ofpostgres list foreign keys on tablepostgress list foreign key postgres find foreign key referencespostgresql show table foreign keyspg list foreign keyspostgres field create list of foreign keyspostgresql foreign key list columnbview foreign keys posgresspostgresql list of foreign keyspostgresql find foreign key referenceshow can i list all foreign keys referencing a given table in postgresshow foreign key postgresqlpostgresql colum that is a list of foreign keyspsql how to get info from foeign key in foreign keyhow to get foreign key column name in postgres of a tableget all foreign key constrains for postgrespostgres get foreign key name from columnspostgresql foreign key list columnpostgresql get all foreign key references with table namehow to find your table foreign key in postgrespostgres field list of foreign keyspostgres get all foreign keys on tablelist fk from table postgrespostgresql get all foreign keysconstraints postgres to obtain all foreign keyshow all foreign key constatins of a postgres databasepostgresql get foreign key columnspostgresql get all foreign key referencespostgresql list table foreign keyspostgres get all foreign key references to columnget foreign key of table postgresview foreign keys of table postgresqlfind table by fk postgresfind table from foreign key postgrespostgresql foreign key listget foreign keys of table postgresforeign key postgresql list fieldhow to check the foregin key postgrespostgresql get all foreign keys that reference a given tablehow to get the foreign keys of a table in sql postgrespostgresql list all foreign key constraintslist all foreign keys for a table postgres