Received: from druid.net (druid.net [216.126.72.98]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5JCaUa56066 for ; Tue, 19 Jun 2001 08:36:30 -0400 (EDT) (envelope-from darcy@druid.net) Received: by druid.net (Postfix, from userid 1000) id F01A21A78; Tue, 19 Jun 2001 08:36:25 -0400 (EDT) Subject: Re: About primary keys. In-Reply-To: <3B2F4128.D9D38897@ac-rouen.fr> "from David BOURIAUD at Jun 19, 2001 02:10:16 pm" To: David BOURIAUD Date: Tue, 19 Jun 2001 08:36:25 -0400 (EDT) Cc: "pgsql-sql@postgresql.org" X-Mailer: ELM [version 2.4ME+ PL78 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Message-Id: <20010619123625.F01A21A78@druid.net> From: darcy@druid.net (D'Arcy J.M. Cain) X-Archive-Number: 200106/287 X-Sequence-Number: 3550 Thus spake David BOURIAUD > Is there a way to get in system tables all the primary keys of a table ? > Thanks by advance. SELECT pg_class.relname, pg_attribute.attname FROM pg_class, pg_attribute, pg_index WHERE pg_class.oid = pg_attribute.attrelid AND pg_class.oid = pg_index.indrelid AND pg_index.indkey[0] = pg_attribute.attnum AND pg_index.indisprimary = 't' Caveat: Does not work for complex primary keys. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.