Re: SELECT <all fields except "bad_field"> from mytbl;

From: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT <all fields except "bad_field"> from mytbl;
Date: 2007-05-31 11:52:11
Message-ID: 1180612331.513713.248390@m36g2000hse.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On May 30, 6:48 am, Rodrigo De León <rdele(dot)(dot)(dot)(at)gmail(dot)com> wrote:

> You might want to add:
>
> AND a.attnum >=1
>
> to remove "tableoid" and friends from the output.

Now I know why I did not get tableoid & friends: because I am querying
a view which does not yield these fields. But to be on the save side,
the clause should be added. So the complete plpgsql code example looks
like this now (in cleaner format):

EXECUTE
'SELECT '
|| SELECT array_to_string(ARRAY(
SELECT a.attname
FROM pg_class c, pg_namespace nc, pg_attribute a
WHERE nc.oid = c.relnamespace
AND a.attrelid = c.oid
AND a.attnum >= 1
AND nc.nspname = 'myschema'
AND c.relname = 'mytbl'
AND a.attname <> 'bad_field'
ORDER by a.attnum), ', ')
|| ' FROM myschema.mytbl';

Regards
Erwin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2007-05-31 12:06:33 Re: stable functions
Previous Message Vincenzo Romano 2007-05-31 11:38:49 Re: stable functions