Обсуждение: how do I do to get the foreign keys of a table?

Поиск
Список
Период
Сортировка

how do I do to get the foreign keys of a table?

От
"Roberto (SmartBit)"
Дата:
This is my SQL to return the constraints...

select tgconstrname, tr.relname, fr.relname from pg_trigger, pg_class tr,
pg_class fr
where tr.oid = tgrelid and fr.oid = tgconstrrelid and
tr.relname='MyTableName'

 so, how do I do to get the  foreign keys of a table?

let me be more explicite, I want to get the name of fields from a table that
are related with other table! (foreign key)

NOTE: I want a SQL command to get it from any table of any PostgreSQL
database, so it can not be a function!

please help me

tia

Roberto de Amorim


Re: how do I do to get the foreign keys of a table?

От
Stephan Szabo
Дата:
On Sat, 19 Oct 2002, Roberto (SmartBit) wrote:

> This is my SQL to return the constraints...
>
> select tgconstrname, tr.relname, fr.relname from pg_trigger, pg_class tr,
> pg_class fr
> where tr.oid = tgrelid and fr.oid = tgconstrrelid and
> tr.relname='MyTableName'
>
>  so, how do I do to get the  foreign keys of a table?
>
> let me be more explicite, I want to get the name of fields from a table that
> are related with other table! (foreign key)

You'll have to parse it out from tgargs.