Re: Exclude fields from SELECT command

From: Steve Midgley <science(at)misuse(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Cc: Charles Tam <c(dot)tam(at)osm(dot)net(dot)au>
Subject: Re: Exclude fields from SELECT command
Date: 2009-03-17 18:49:44
Message-ID: 20090317185015.5328B634D4F@mail.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 05:20 PM 3/16/2009, pgsql-sql-owner(at)postgresql(dot)org wrote:
>In-Reply-To: <1992170861895942422(at)unknownmsgid>
>References: <1992170861895942422(at)unknownmsgid>
>Date: Mon, 16 Mar 2009 22:45:54 +0100
>Message-ID:
><162867790903161445i78127316s1c0deb3bec0e15e5(at)mail(dot)gmail(dot)com>
>Subject: Re: Exclude fields from SELECT command
>From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>To: Charles Tam <c(dot)tam(at)osm(dot)net(dot)au>
>Cc: pgsql-sql(at)postgresql(dot)org
>
>2009/3/16 Charles Tam <c(dot)tam(at)osm(dot)net(dot)au>:
> > Hi Everybody
> >
> >
> >
> > I’ve a table with 35 fields and would like
> to perform a SELECT command
> > without specifying every single field.
> >
> > As such, I’ve use the SELECT *
> command. Is there an approach to exclude 5
> > fields from being returned?
> >
> >
> >
>
>hello
>
>no, there are no way
>
>regards
>Pavel Stehule

I think Pavel is right for 99% of the cases. But
there is a "cure that is worse than the disease."

You could select all columns from a bunch of
tables without knowing what the column names
were, excepting N columns, by iterating through
the info schema data and building a SQL select
appropriately (sql meta-programming I guess you
would call it). But it's a real chore to do
manually. If you have this need for some
programmatic purpose (where some initial
investment in effort will pay future dividends),
then check out the info schema options:

http://developer.postgresql.org/pgdocs/postgres/infoschema-columns.html

In your case, I think you'd be looking for five
values of "table_name" and then looking at all
the "column_name" fields, building your column
list, excepting the column_names you wish to exclude..

Best,

Steve

Browse pgsql-sql by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2009-03-17 21:40:08 join
Previous Message Tom Lane 2009-03-17 16:56:40 Re: Methods declaration