Re: How to identify which column in a table is the primary key

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Scot L(dot) Harris" <webid(at)cfl(dot)rr(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to identify which column in a table is the primary key
Date: 2004-06-01 19:23:01
Message-ID: 4938.1086117781@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Scot L. Harris" <webid(at)cfl(dot)rr(dot)com> writes:
> So given the table name is there a way to identify the column defined as
> the primary key for that table?

You need to look in pg_index.

Note that the primary key could be a multicolumn index, so starting with
the assumption that there is "the column" is going to lead you on the
wrong track.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mike Nolan 2004-06-01 20:03:51 Re: Running Totals and other stuff....
Previous Message Frank Finner 2004-06-01 18:27:41 Re: Disappointing news