Retrieve the primary key of a table

From: Alejandro <apinoo(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Retrieve the primary key of a table
Date: 2009-08-03 02:24:44
Message-ID: 86eeef650908021924q3012d8e6saabfcda70349850b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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.

Thanks, Alejandro.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Lacey Powers 2009-08-03 06:21:39 Re: Retrieve the primary key of a table
Previous Message Jason Stelzel 2009-07-31 05:16:58 Re: Synchronizing the schema of two PostgreSQL databases