Re: Finding the primary key of tables

From: Devrim GÜNDÜZ <devrim(at)gunduz(dot)org>
To: George Silva <georger(dot)silva(at)gmail(dot)com>
Cc: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Finding the primary key of tables
Date: 2010-08-03 19:33:40
Message-ID: 1280864020.2667.11.camel@hp-laptop2.gunduz.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2010-08-03 at 16:13 -0300, George Silva wrote:
> I'm building a function which needs to know what is the primary key of
> a
> certain table (all in pgplsql).
>
> I was using select * from information_schema.key_column_usage where
> table_schema='foo' and table_name = 'aaa'; but that will give me
> multiple
> results in case of additional keys in the table.
>
> Any suggestions?

See pg_index.indisprimary column. If it is true, then the it is the PK
of given table.

Regards,
--
Devrim GÜNDÜZ
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
PostgreSQL RPM Repository: http://yum.pgrpms.org
Community: devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.gunduz.org Twitter: http://twitter.com/devrimgunduz

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message George Silva 2010-08-03 19:38:04 Re: Finding the primary key of tables
Previous Message David Kerr 2010-08-03 19:33:33 Re: Question about Idle in TX