From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] how can tell if a column is a primary key?
Date: Mon, 15 Nov 1999 10:24:16 -0500
Message-ID: <18416.942679456@sss.pgh.pa.us> (raw)
In-Reply-To: <m11nLKh-0000bFC@druid.net>
"D'Arcy" "J.M." Cain <darcy@druid.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: [SQL] how can tell if a column is a primary key?
In-Reply-To: <18416.942679456@sss.pgh.pa.us>
References: <m11nLKh-0000bFC@druid.net> <18416.942679456@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox