Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id KAA13311 for ; Mon, 15 Nov 1999 10:24:47 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id KAA18418 for ; Mon, 15 Nov 1999 10:24:16 -0500 (EST) To: pgsql-sql@postgreSQL.org Subject: Re: [SQL] how can tell if a column is a primary key? In-reply-to: Your message of Mon, 15 Nov 1999 07:34:06 -0500 (EST) Date: Mon, 15 Nov 1999 10:24:16 -0500 Message-ID: <18416.942679456@sss.pgh.pa.us> From: Tom Lane "D'Arcy" "J.M." Cain 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