Re: all non-PK columns from information schema

From: Tarlika Elisabeth Schmitz <postgresql6(at)numerixtechnology(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: all non-PK columns from information schema
Date: 2011-11-15 16:00:07
Message-ID: 20111115160007.527f9aa1@dick.coachhouse
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 15 Nov 2011 09:26:35 -0600
Mike Blackwell <mike(dot)blackwell(at)rrd(dot)com> wrote:

>On Tue, Nov 15, 2011 at 02:59, Tarlika Elisabeth Schmitz <
>postgresql6(at)numerixtechnology(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message LPlateAndy 2011-11-15 16:23:27 Re: encoding and LC_COLLATE
Previous Message Raymond O'Donnell 2011-11-15 13:26:47 Re: EXECUTE USING problem