Re: how to find primary key field name?

From: Joe Abbate <jma(at)freedomcircle(dot)com>
To: "J(dot)V(dot)" <jvsrvcs(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to find primary key field name?
Date: 2011-10-11 23:03:28
Message-ID: 4E94CB40.8070505@freedomcircle.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/11/2011 06:54 PM, J.V. wrote:
> If I have a table name, I know how to find the primary key constraint
> name, but see no way to find the primary key field name.
>
> select constraint_name from information_schema.tabale_constraints where
> table_name = <table_name> and constraint_type = 'PRIMARY KEY';
>
> will return the constraint name, but given the table_name and the
> constraint_name, how do I find the database column/field name associated
> with that primary key?

If you query pg_constraint as I showed you before, you can also get
conkey which is an array of smallints pointing at the columns (in
pg_attribute) that form the key.

Joe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message J.V. 2011-10-11 23:24:50 Re: how to save primary key constraints
Previous Message Adrian Klaver 2011-10-11 23:02:52 Re: how to find primary key field name?