Search Postgresql Archives

Re: fields and foreign keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 23, 2005 at 01:34:28AM -0700, mrix wrote:
> 
> I'd like to know how can i get list of fields and corresponding foreign
> keys (referenced table and field).

For individual tables, client interfaces usually have a way to show
the table definition.  In psql, for example, you can use "\d tablename".
If you want to see all foreign key constraints for all tables then
you could query the pg_constraint system catalog.

http://www.postgresql.org/docs/8.0/static/catalog-pg-constraint.html

You can get an idea of what query to issue by viewing the hidden commands
that psql executes (run "psql -E" or execute "\set ECHO_HIDDEN" and then
execute "\d tablename").  Here's an example:

SELECT conrelid::regclass, conname, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE contype = 'f';

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux