Re: [SQL] how can tell if a column is a primary key?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] how can tell if a column is a primary key?
Date: 1999-11-15 15:24:16
Message-ID: 18416.942679456@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"D'Arcy" "J.M." Cain <darcy(at)druid(dot)net> writes:
> Here's another FAQ but one that no one has ever answered that I know of.
> How do I generalize the above query so that it returns information on
> all the elements of complex keys?

indkey and indclass are type int28 and oid8 respectively, which are
almost like 8-element arrays, except that for historical reasons they
index from 0 not 1. So instead of pg_index.indkey[0] = pg_attribute.attnum
write pg_index.indkey[1] = pg_attribute.attnum to find attributes that
are secondary index columns, [2] for tertiary, etc. Unused positions
in indkey[] are filled with zeroes.

If you have code on the client side it'd probably make most sense just
to pull back the whole value of indkey[] and then issue separate SELECTs
to find out what the referenced attributes are, instead of probing 8
times to see if you get anything...

BTW, if indproc is nonzero then you are looking at a functional index,
and in that case the indkey[] array describes the arguments to the
function; there is only one index column, namely the function result.

regards, tom lane

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Lockhart 1999-11-15 15:29:43 Re: [SQL] nulls and datetime
Previous Message D'Arcy J.M. Cain 1999-11-15 12:34:06 Re: [SQL] how can tell if a column is a primary key?