Description
From [email protected] on February 05, 2010 15:16:23
Hi,
In postgres constraint names can be named $1, $2, etc.. As a result,
constraint name is not unique. There can be 2 tables with 2 constraints
named $1 for example.
Thats why joining information_schema.table_constraints and
information_schema.constraint_column_usage on constraint_name will bring
not relevant results.
here is my solution for this -
select
--conname,
--t.relname as table,
tf.relname as references_table,
a.attname as column_name,
af.attname as references_field
from
pg_constraint c,
pg_attribute a,
pg_attribute af,
pg_stat_user_tables t,
pg_stat_user_tables tf
where
c.contype='f' and
c.conkey[1]=a.attnum and
c.conrelid=a.attrelid and
c.confkey[1]=af.attnum and
c.confrelid=af.attrelid and
t.relid=c.conrelid and
tf.relid=c.confrelid
and t.relname='".$table."' and a.attname='".$name."'
regards,
Sergey
Original issue: http://code.google.com/p/wwwsqldesigner/issues/detail?id=62