Re: SQL Query to get Column constraints

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Steve" <svanspal(at)bigpond(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: SQL Query to get Column constraints
Date: 2003-04-03 18:12:41
Message-ID: 11566.1049393561@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Steve" <svanspal(at)bigpond(dot)com> writes:
> What I need to know, is how to find out if a column is a primary, or part of
> a primary key. I need to do this using sql.

In 7.3 this is pretty easy: look in the pg_constraint table for a 'p'
constraint for the table. If you find one, 'conkey' lists the column
numbers of the key columns. In prior versions you'd need to look in
pg_index instead. (Actually the pg_index method still works, but it's
messier.)

See the "System Catalogs" chapter of the documentation.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-04-03 18:16:42 Re: gmake does not finish on default slackware 9 (or 8.1) install
Previous Message Merlin Moncure 2003-04-03 18:12:12 Re: [HACKERS] OSS database needed for testing