From: | "Nick Barr" <nicky(at)chuckie(dot)co(dot)uk> |
---|---|
To: | "Brendan Jurd" <blakjak(at)blakjak(dot)sytes(dot)net>, <mike(dot)griffin(at)mygenerationsoftware(dot)com> |
Cc: | "PostgreSQL-general" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Can you help me with this query? |
Date: | 2004-06-16 10:22:15 |
Message-ID: | 003301c4538b$cdd93420$3202a8c0@webbased10 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
<snip>
>
> create or replace function getattnames(oid, smallint[])
> returns name[] as '
> select array(select attname from pg_attribute
> where attrelid = $1
> and attnum = any ($2))
> ' language sql;
>
> SELECT cl.relname as TABLE_NAME,
> cr.relname as FK_TABLE_NAME,
> getattnames(ct.conrelid, ct.conkey) as TBL_ATTS,
> getattnames(ct.confrelid, ct.confkey) as FK_TBL_ATTS
> FROM pg_constraint ct
> JOIN pg_class cl ON cl.oid=conrelid
> JOIN pg_namespace nl ON nl.oid=cl.relnamespace
> JOIN pg_class cr ON cr.oid=confrelid
> JOIN pg_namespace nr ON nr.oid=cr.relnamespace
> LEFT OUTER JOIN pg_description des ON des.objoid=ct.oid
> WHERE contype='f';
>
How about:
SELECT cl.relname as TABLE_NAME,
cr.relname as FK_TABLE_NAME,
(select array(select attname from pg_attribute
where attrelid = ct.conrelid
and attnum = any (ct.conkey))) AS TBL_ATTS,
(select array(select attname from pg_attribute
where attrelid = ct.confrelid
and attnum = any (ct.confkey))) AS FK_TBL_ATTS
FROM pg_constraint ct
JOIN pg_class cl ON cl.oid=conrelid
JOIN pg_namespace nl ON nl.oid=cl.relnamespace
JOIN pg_class cr ON cr.oid=confrelid
JOIN pg_namespace nr ON nr.oid=cr.relnamespace
LEFT OUTER JOIN pg_description des ON des.objoid=ct.oid
WHERE contype='f';
Note the function is no longer there ;-)
Nick
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2004-06-16 10:24:19 | Re: 7.4 performance issue |
Previous Message | Thomas | 2004-06-16 10:17:21 | PostGres ODBC MFC Application |