pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: rcolmegna@tiscali.it <rcolmegna@tiscali.it>
Cc: pgsql-sql@postgresql.org
Subject: Re: R: Re: R: R: Re: schema inspection
Date: Fri, 17 Mar 2006 12:21:34 +0200 (EET)
Message-ID: <Pine.LNX.4.44.0603171208490.27392-100000@matrix.gatewaynet.com> (raw)
In-Reply-To: <19570915.1142585814389.JavaMail.root@ps20>

O rcolmegna@tiscali.it Ýãñáøå óôéò Mar 17, 2006 :

> >
> >SELECT c1.relname,c2.relname from pg_constraint cons,pg_class c1, 
> pg_class
> >c2 where cons.conrelid=c1.oid and cons.confrelid = c2.oid;
> >
> >for column(s) names you will have to do extra homework.
> 
> Thanks!   I have obtained my query! Here is:
> 
> SELECT 
>   (SELECT relname FROM pg_catalog.pg_class WHERE oid=conrelid) AS 
> fromTbl,
>   (SELECT relname FROM pg_catalog.pg_class WHERE oid=confrelid) AS 
> toTbl,
>   (SELECT attname FROM pg_catalog.pg_attribute WHERE attrelid=conrelid 
> AND conkey[1]=attnum) AS viaCol
> FROM pg_catalog.pg_constraint AS rel WHERE contype='f';

Well thats it if you use only *single column* Foreign keys.
In the general case the above will need extra work.

Of course you will also have to ensure that the constraint is indeed
a FK constraint, that the column is not droped, etc....
which leads to the answer that enabling statement logging,
and then \d and watching the log is a very good friend too.

> 
> TIA
> Roberto Colmegna
> 
> 
> 
> 		
> Tiscali ADSL 4 Mega Flat
> Naviga senza limiti con l'unica Adsl a 4 Mega di velocità a soli 19,95 € al mese!
> Attivala subito e hai GRATIS 2 MESI e l'ATTIVAZIONE. 
> http://abbonati.tiscali.it/banner/middlepagetracking.html?c=webmailadsl&r=http://abbonati.tiscal...
> 

-- 
-Achilleus




view thread (3+ messages)  latest in thread

Message-ID: <Pine.LNX.4.44.0603171208490.27392-100000@matrix.gatewaynet.com>
Permalink:  ../Pine.LNX.4.44.0603171208490.27392-100000@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.44.0603171208490.27392-100000@matrix.gatewaynet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: achill@matrix.gatewaynet.com, rcolmegna@tiscali.it
  Subject: Re: R: Re: R: R: Re: schema inspection
  In-Reply-To: <Pine.LNX.4.44.0603171208490.27392-100000@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox