Στις Τρίτη 19 Δεκέμβριος 2006 16:01, ο/η Carlos Santos έγραψε: > Hi! > I need to query a select that returns all the fields of an specific primary > 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 = 'foo';
First by SELECT pgc.conkey from pg_class pgcl,pg_constraint pgc where pgcl.relname='your table name' and pgcl.oid=pgc.conrelid and pgc.contype='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 where pgcl.relname='your table name' and pgcl.oid=pgc.conrelid and pgc.contype='p' and pgat.attrelid=pgcl.oid and attnum=pgc.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�tica > Santa Rita do Sapuca� - MG > www.compels.net > > > > > > > _______________________________________________________ > O Yahoo! est� de cara nova. Venha conferir! > http://br.yahoo.com -- Achilleas Mantzios ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly