Re: Aliases for Field Names in SELECT statements

From: merlyn(at)stonehenge(dot)com (Randal L(dot) Schwartz)
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pdxpug(at)postgresql(dot)org
Subject: Re: Aliases for Field Names in SELECT statements
Date: 2008-01-04 17:24:30
Message-ID: 86sl1d5ws1.fsf@blue.stonehenge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pdxpug

>>>>> "Randal" == Randal L Schwartz <merlyn(at)stonehenge(dot)com> writes:

>>>>> "Rich" == Rich Shepard <rshepard(at)appl-ecosys(dot)com> writes:
Rich> A thread on the postgres users mail list asks how to write a SELECT
Rich> statement using a column alias (e.g., SELECT emp_id AS e FROM employee),
Rich> and Bruce Momjian responded that it's not possible and on the To-Do list
Rich> to not be done.

Randal> Are you sure he wasn't talking about the fact that in the standard, aliases
Randal> apply *after* the WHERE, but *before* the HAVING, and therefore you can't ever
Randal> use aliases in the WHERE clause since they simply don't exist yet?

Ahh, just checked out the thread. The problem is not the aliases: they're
fully supported according to the spec.

The problem is the optional "AS" keyword. Other SQLs permit:

SELECT foo bar FROM atable;

to mean

SELECT foo AS bar FROM atable;

The problem is that permitting optional "AS" means that Pg with its
unique postfix operators would be ambiguous. If + was a postfix
operator, would:

SELECT foo + bar FROM atable;

mean that "foo +" is being aliased to bar, or that the column is
foo + bar?

Interesting problem.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(at)stonehenge(dot)com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

In response to

Responses

Browse pdxpug by date

  From Date Subject
Next Message Selena Deckelmann 2008-01-04 17:27:40 Meeting topics - for the next six months!
Previous Message Randal L. Schwartz 2008-01-04 17:18:50 Re: Aliases for Field Names in SELECT statements