Skip site navigation (1) Skip section navigation (2)

Re: How to detect primary key of a table

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Sergey Karin <sergey(dot)karin(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to detect primary key of a table
Date: 2006-03-30 11:40:48
Message-ID: 20060330114048.GA7391@winnie.fuhr.org (view raw or flat)
Thread:
Lists: 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

In response to

pgsql-general by date

Next:From: jayati.biswasDate: 2006-03-30 11:55:34
Subject: Recovery with pg_xlog
Previous:From: Martijn van OosterhoutDate: 2006-03-30 11:38:07
Subject: Re: converting timstamptz to local time zone

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group