Re: all non-PK columns from information schema - Mailing list pgsql-general

From Tarlika Elisabeth Schmitz
Subject Re: all non-PK columns from information schema
Date
Msg-id 20111115160007.527f9aa1@dick.coachhouse
Whole thread Raw
In response to all non-PK columns from information schema  (Tarlika Elisabeth Schmitz <postgresql6@numerixtechnology.de>)
Responses Re: all non-PK columns from information schema
List pgsql-general
On Tue, 15 Nov 2011 09:26:35 -0600
Mike Blackwell <mike.blackwell@rrd.com> wrote:

>On Tue, Nov 15, 2011 at 02:59, Tarlika Elisabeth Schmitz <
>postgresql6@numerixtechnology.de> wrote:
>
>> I'd  like to select all column names for a specific table except
>> those that are part of the PK.
>> --
>> Tarlika Elisabeth Schmitz
>>
>I'd probably use the system catalogs.  See
>http://www.postgresql.org/docs/9.1/interactive/catalogs.html
>
>You could do something along the lines of:
>
>select attname from pg_class t
>join pg_attribute on (attrelid = t.oid)
>where attnum > 0
>and not exists (select 1 from pg_constraint where conrelid = t.oid and
>attnum = any(conkey) and contype = 'p')
>and relname = 'table_of_interest'
>__________________________________________________________________________________
>*Mike Blackwell | Technical Analyst, Distribution Services/Rollout

Thanks for the reply, Mike.
Interesting. I have previously used the information_schema for similar
queries.

What are the pros and cons for using either pg_catalog or
information_schema?

--

Best Regards,
Tarlika Elisabeth Schmitz

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: EXECUTE USING problem
Next
From: LPlateAndy
Date:
Subject: Re: encoding and LC_COLLATE