Re: Locating ( FKs ) References to a Primary Key

From: Roger Tannous <roger77_lb(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Locating ( FKs ) References to a Primary Key
Date: 2005-08-18 05:58:21
Message-ID: 20050818055821.34703.qmail@web51902.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dmitri,

Thanks !! I got exactly what I wanted :)

In fact, I used your query like this:

SELECT
cl.relname AS FK_table_name,
a.attname AS FK_column_name,
clf.relname AS PK_table_name,
af.attname AS PK_column_name
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class cl ON (a.attrelid = cl.oid AND cl.relkind =
'r')
JOIN pg_catalog.pg_namespace n ON (n.oid = cl.relnamespace)
JOIN pg_catalog.pg_constraint ct ON (a.attrelid = ct.conrelid AND
ct.confrelid != 0 AND ct.conkey[1] = a.attnum)
JOIN pg_catalog.pg_class clf ON (ct.confrelid = clf.oid AND clf.relkind
= 'r')
JOIN pg_catalog.pg_namespace nf ON (nf.oid = clf.relnamespace)
JOIN pg_catalog.pg_attribute af ON (af.attrelid = ct.confrelid AND
af.attnum = ct.confkey[1])
WHERE n.nspname = nf.nspname AND n.nspname = 'public' AND clf.relname like
'sip_emp' AND af.attname = 'id';

Best Regards,
Roger Tannous.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Browne 2005-08-18 12:58:07 Re: How to secure PostgreSQL Data for distribute?
Previous Message Chris Travers 2005-08-18 05:26:59 Re: How to secure PostgreSQL Data for distribute?