Skip site navigation (1) Skip section navigation (2)

Re: alter table add column - specify where the column will go?

From: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>
To: Florian Weimer <fweimer(at)bfk(dot)de>
Cc: Dmitriy Igrishin <dmitigr(at)gmail(dot)com>, Alexander Farber <alexander(dot)farber(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: alter table add column - specify where the column will go?
Date: 2010-11-24 11:13:30
Message-ID: AANLkTi=3DwXqds2SPvkmZrXmq1qbqUdJkwFTFzeyzHGW@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
2010/11/24 Florian Weimer <fweimer(at)bfk(dot)de>:
> * Grzegorz Jaśkiewicz:
>
>> just never use SELECT *, but always call columns by names. You'll
>> avoid having to depend on the order of columns, which is never
>> guaranteed, even if the table on disk is one order, the return columns
>> could be in some other.
>
> This can't be true because several SQL features rely on deterministic
> column order.  Here's an example:
>
> SELECT 1 AS a, 2 AS b UNION SELECT 3 AS b, 4 AS a;
>
>  a | b
> ---+---
>  1 | 2
>  3 | 4
> (2 rows)
>

Read again what I wrote please.

Yes, most DBs do a good job to keep it consistent, but they don't have
to. So unless you specify column names explicitly (like you did in the
example above), there's no guarantees.

Most people struggle with long table names in joins and stuff, for
instance: SELECT foo.one, bar.two FROM foo join ... Because they
forget about the aliases, like SELECT a.one, b.two FROM foo a JOIN bar
b ..



-- 
GJ

In response to

Responses

pgsql-general by date

Next:From: Florian WeimerDate: 2010-11-24 11:31:27
Subject: Re: alter table add column - specify where the column will go?
Previous:From: Florian WeimerDate: 2010-11-24 11:06:09
Subject: Re: alter table add column - specify where the column will go?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group