SELECT'K'AS key_flag, t.table_name AS k_tablename, l.column_name AS k_column_name, k.table_name AS f_table_name, k.column_name AS f_coumn_name, t.constraint_name
FROM information_schema.constraint_table_usage t
JOIN information_schema.constraint_column_usage l ON t.constraint_name::text = l.constraint_name::text
JOIN information_schema.key_column_usage k ON t.constraint_name::text = k.constraint_name::text
JOIN information_schema.table_constraints c ON t.constraint_name::text = c.constraint_name::text
WHERE c.constraint_type::text ='FOREIGN KEY'::text
UNIONALLSELECT'F'AS key_flag, k.table_name AS k_tablename, k.column_name AS k_column_name, t.table_name AS f_table_name, l.column_name AS f_coumn_name, t.constraint_name
FROM information_schema.key_column_usage k
JOIN information_schema.table_constraints c ON k.constraint_name::text = c.constraint_name::text
JOIN information_schema.constraint_table_usage t ON k.constraint_name::text = t.constraint_name::text
JOIN information_schema.constraint_column_usage l ON t.constraint_name::text = l.constraint_name::text
WHERE c.constraint_type::text ='FOREIGN KEY'::text
ORDERBY 2, 1 DESC;
Почитайте это в Мануале.
Почитайте это в Мануале. Может поможет:
http://postgresql.ru.net/manual/catalog-pg-constraint.html
Ну как-то так: SELECT 'K' AS
Ну как-то так: