From: | Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com> |
---|---|
To: | Carlos Santos <carlos(at)compels(dot)net>, PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Query a select that returns.... |
Date: | 2006-12-19 15:05:01 |
Message-ID: | 200612191705.01684.achill@matrix.gatewaynet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Στις Τρίτη 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 Informtica
> Santa Rita do Sapuca - MG
> www.compels.net
>
>
>
>
>
>
> _______________________________________________________
> O Yahoo! est de cara nova. Venha conferir!
> http://br.yahoo.com
--
Achilleas Mantzios
From | Date | Subject | |
---|---|---|---|
Next Message | George Pavlov | 2006-12-19 18:59:17 | Re: null values in non-nullable column |
Previous Message | Markus Schaber | 2006-12-19 14:57:03 | Re: null values in non-nullable column |