Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 720889FA0EE for ; Tue, 19 Dec 2006 11:05:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 66529-01 for ; Tue, 19 Dec 2006 11:05:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by postgresql.org (Postfix) with ESMTP id 285BD9F9FE1 for ; Tue, 19 Dec 2006 11:05:06 -0400 (AST) Received: from host3.dynacom.ondsl.gr ([62.103.35.211] helo=ip216.internal.net) by matrix.gatewaynet.com with esmtp (Exim 4.62) (envelope-from ) id 1GwgWc-0001KJ-83; Tue, 19 Dec 2006 17:05:02 +0200 From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: Carlos Santos , PostgreSQL SQL Subject: Re: Query a select that returns.... User-Agent: KMail/1.9.3 References: <20061219140105.74337.qmail@web57103.mail.re3.yahoo.com> In-Reply-To: <20061219140105.74337.qmail@web57103.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Disposition: inline Date: Tue, 19 Dec 2006 17:05:01 +0200 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <200612191705.01684.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/136 X-Sequence-Number: 27092 =CE=A3=CF=84=CE=B9=CF=82 =CE=A4=CF=81=CE=AF=CF=84=CE=B7 19 =CE=94=CE=B5=CE= =BA=CE=AD=CE=BC=CE=B2=CF=81=CE=B9=CE=BF=CF=82 2006 16:01, =CE=BF/=CE=B7 Car= los Santos =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > Hi! > I need to query a select that returns all the fields of an specific prima= ry > key, but I don't have the single column's name that is constrained as > primary key. How can I do that? > Something like: > SELECT * FROM myTable WHERE myTable.pkey =3D 'foo'; =46irst by SELECT pgc.conkey from pg_class pgcl,pg_constraint pgc where=20 pgcl.relname=3D'your table name' and pgcl.oid=3Dpgc.conrelid and pgc.contyp= e=3D'p'; you get the attribute numbers of the primary key. Then you have to lookup pg_attribute to find the column names. In the simplified case where the primary key is consisted of only one attribute (column), then SELECT pgat.attname from pg_class pgcl,pg_constraint pgc,pg_attribute pgat= =20 where pgcl.relname=3D'your table name' and pgcl.oid=3Dpgc.conrelid and=20 pgc.contype=3D'p' and pgat.attrelid=3Dpgcl.oid and attnum=3Dpgc.conkey[1]; should give you the attribute name of the primary key. Then you build your query from your program accordingly. > > Thanks > > Carlos Henrique Iazzetti Santos > Compels Inform=E1tica > Santa Rita do Sapuca=ED - MG > www.compels.net > > > > > > > _______________________________________________________ > O Yahoo! est=E1 de cara nova. Venha conferir! > http://br.yahoo.com =2D-=20 Achilleas Mantzios