From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Kevin Murphy <murphy(at)genome(dot)chop(dot)edu> |
Cc: | pgsql-general General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Aliasing syntax question |
Date: | 2009-02-19 17:46:14 |
Message-ID: | 10219.1235065574@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Kevin Murphy <murphy(at)genome(dot)chop(dot)edu> writes:
> Substitute the following pairs of values for X and Y in the query below,
> and all of them work (in PG 8.3.6, at least):
> X Y
> g g
> i g(i)
> g g(i)
> g.i g(i)
> create or replace function unnest(anyarray)
> returns setof anyelement as $$
> select $1[X] from generate_series(array_lower($1,1),array_upper($1,1)) Y;
> $$ language sql;
The reason they all work is that generate_series() returns a scalar
(ie, an integer). In all these cases the table alias "g" would
resolve as the function's whole-tuple result, but that's just an
integer. We also provide a column alias for the scalar value,
which is why cases 2 and 4 work.
In case 1 the alias Y is really being read as g(g), so you could also
have written X as g.g if you like being pedantic. I think BTW that the
unqualified reference to g will be resolved preferentially as being a
column alias not a table alias, but you end up at the same result either
way for a scalar function.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Richardson | 2009-02-19 17:46:41 | Search for text in any function |
Previous Message | SHARMILA JOTHIRAJAH | 2009-02-19 17:40:49 | Re: How to pipe the psql copy command to Unix 'Date' command |