Re: How to detect primary key of a table - Mailing list pgsql-general

From Michael Fuhr
Subject Re: How to detect primary key of a table
Date
Msg-id 20060330114048.GA7391@winnie.fuhr.org
Whole thread Raw
In response to How to detect primary key of a table  ("Sergey Karin" <sergey.karin@gmail.com>)
List pgsql-general
On Thu, Mar 30, 2006 at 03:13:12PM +0400, Sergey Karin wrote:
> Are there any abilities to detect primary key of a table?

In psql you could use "\d tablename".  To see the queries that psql
makes, execute "\set ECHO_HIDDEN" and then "\d tablename".  Here's
the documentation for the system catalogs that psql queries:

http://www.postgresql.org/docs/8.1/interactive/catalogs.html

You could also query the Information Schema; table_constraints
joined with key_column_usage or constraint_column_usage should
yield a table's primary key columns.

http://www.postgresql.org/docs/8.1/interactive/information-schema.html

--
Michael Fuhr

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: converting timstamptz to local time zone
Next
From: "Tass Chapman"
Date:
Subject: Chasing "signal 11" issues