Re: Finding the primary key of tables

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
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:32:11
Message-ID: AANLkTinfcWxQ43uxK65tRAXYStAM5xBm91a7=rDz44zn@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Aug 3, 2010 at 3:13 PM, George Silva <georger(dot)silva(at)gmail(dot)com> wrote:
> Hello guys,
>
> 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?

take a look at information_schema.table_constraint and match on constraint_name.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Kerr 2010-08-03 19:33:33 Re: Question about Idle in TX
Previous Message Greg Smith 2010-08-03 19:30:46 Re: Question about Idle in TX