From: | Michael Wood <esiotrot(at)gmail(dot)com> |
---|---|
To: | Alejandro <apinoo(at)gmail(dot)com> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Retrieve the primary key of a table |
Date: | 2009-08-03 12:58:13 |
Message-ID: | 5a8aa6680908030558h3e356ec9ifc12ba97149bd88c@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi
2009/8/3 Alejandro <apinoo(at)gmail(dot)com>:
> Hi. I need to retrieve the primary key of a table and their value.
>
> I tried with this
> http://wiki.postgresql.org/wiki/Retrieve_primary_key_columns:
>
> SELECT
> pg_attribute.attname,
> format_type(pg_attribute.atttypid, pg_attribute.atttypmod)
>
> FROM pg_index, pg_class, pg_attribute
> WHERE
> pg_class.oid = 'TABLENAME'::regclass AND
>
> indrelid = pg_class.oid AND
> pg_attribute.attrelid = pg_class.oid AND
>
> pg_attribute.attnum = any(pg_index.indkey);
>
> But this shows indexes too.
> http://wiki.postgresql.org/wiki/Talk:Retrieve_primary_key_columns
>
> How can I get only the primary key?
>
> I have postgres 8.1.11.
If you run "psql -E" it will show you all the queries it runs when you
type "\d tablename" and other similar commands. I think you should be
able to work out from that what the query should be.
--
Michael Wood <esiotrot(at)gmail(dot)com>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-08-03 14:14:36 | Re: Retrieve the primary key of a table |
Previous Message | Michel Albert | 2009-08-03 11:06:13 | Re: Index size |