Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4E6A047546C for ; Fri, 16 Aug 2002 12:01:30 -0400 (EDT) Received: from ryloth.acucore.com (unknown [65.204.194.43]) by postgresql.org (Postfix) with SMTP id 4A221475B18 for ; Fri, 16 Aug 2002 12:01:19 -0400 (EDT) Received: (qmail 5418 invoked by uid 508); 16 Aug 2002 15:08:06 -0000 Received: from killroyboy@users.sourceforge.net by ryloth.acucore.com by uid 505 with qmail-scanner-1.10 (hbedv: 6.13.0.4. hbedv: product: AntiVir. hbedv: operating system: Linux (glibc). hbedv: product version: 2.0.2. hbedv: engine version: 6.13.0.4. hbedv: packlib version: 2.0.0.2 (supports 18 formats). hbedv: vdf version: 6.13.0.21. hbedv: registered user: Dan Wilson, Cedar Hills. hbedv: serial number: 1001019348. hbedv: key expires: 31 May 2003. hbedv: run mode: PRIVATE. spamassassin. Clear:0. Processed in 0.907797 secs); 16 Aug 2002 15:08:06 -0000 Received: from localhost (127.0.0.1) by 0 with SMTP; 16 Aug 2002 15:08:05 -0000 Received: from dm1-88.fx.aros.net (dm1-88.fx.aros.net [66.219.223.88]) by webmail.acucore.com (IMP) with HTTP for ; Fri, 16 Aug 2002 09:08:05 -0600 Message-ID: <1029510485.3d5d15554800f@webmail.acucore.com> Date: Fri, 16 Aug 2002 09:08:05 -0600 From: Dan Wilson To: Kevin Gordon Cc: pgsql-php@postgresql.org Subject: Re: [Fwd: Names of columns used by primary key] References: <3D5D4541.3090706@paradise.net.nz> In-Reply-To: <3D5D4541.3090706@paradise.net.nz> MIME-Version: 1.0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) 4.0-cvs X-Priority: 3 (Normal) X-Spam-Status: No, hits=-1.8 required=5.0 tests=IN_REP_TO,DOUBLE_CAPSWORD,MSG_ID_ADDED_BY_MTA_3,AWL version=2.31 X-Spam-Level: X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/61 X-Sequence-Number: 1406 This query should help you out: SELECT ic.relname AS index_name, bc.relname AS tab_name, ta.attname AS column_name, i.indisunique AS unique_key, i.indisprimary AS primary_key FROM pg_class bc, pg_class ic, pg_index i, pg_attribute ta, pg_attribute ia WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND ia.attrelid = i.indexrelid AND ta.attrelid = bc.oid AND bc.relname = '[table_name]' AND ta.attrelid = i.indrelid AND ta.attnum = i.indkey[ia.attnum-1] ORDER BY index_name, tab_name, column_name Of course, be sure to change the "[table_name]". Then all you have to do is check if primary_key is 't' and then get the column name. -Dan Quoting Kevin Gordon : > Question for pqsql-php mail list: > How can I determine the names of the columns that make up the primary > key in a postgresql table? > Your help would be appreciated.