Re: Select all fields except one

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Vivek Khera" <khera(at)kcilink(dot)com>
Cc: "pgsql-general General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Select all fields except one
Date: 2007-11-28 17:50:03
Message-ID: b42b73150711280950k1902e3a0l9c5b975fb7bbc870@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Nov 28, 2007 12:18 PM, Vivek Khera <khera(at)kcilink(dot)com> wrote:
> For best practices, you should never use select * in your queries. You will
> inevitably end up with code that cannot deal with a schema change, and for
> any live system, you will have a schema change at some point...
>
> It is best to explicitly list the field names your code is expecting.
> Besides, I don't think you can do what you want to do with just SQL.

sometimes this is desirable. for example, you may have a view defined
as 'select * from foo' which you want to change with foo...and it is
not too difficult to write application code that is tolerant of adding
extra fields. also it is often useful to expand row and type
variables with '*' although this is kind of a postgresql peculiarity.

also consider 'insert...select' or 'create table as select' statements
that copy data from copy of table to another that by definition take
all the fields...so wouldn't a * be preferable to adjusting the field
list when it changes?

you are generally right though...i'm just laying out some excpetions.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Trevor Talbot 2007-11-28 17:53:34 Re: Linux v.s. Mac OS-X Performance
Previous Message Joshua D. Drake 2007-11-28 17:47:19 Re: Select all fields except one