AS s(a) vs. AS a

Started by Thalis Kalfigkopoulosover 13 years ago2 messagesgeneral
Jump to latest
#1Thalis Kalfigkopoulos
tkalfigo@gmail.com

Hi all.

I see in the docs the following:
SELECT current_date + s.a AS dates FROM generate_series(0,14,7) AS s(a);

Trying it as:
SELECT current_date + a AS dates FROM generate_series(0,14,7) AS a;

yields exactly the same result.

Does the finer granularity/expressiveness offer some extra
functionality in some cases or is it a matter of style?

regards,
--Thalis

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thalis Kalfigkopoulos (#1)
Re: AS s(a) vs. AS a

Thalis Kalfigkopoulos <tkalfigo@gmail.com> writes:

I see in the docs the following:
SELECT current_date + s.a AS dates FROM generate_series(0,14,7) AS s(a);

Trying it as:
SELECT current_date + a AS dates FROM generate_series(0,14,7) AS a;

yields exactly the same result.

Does the finer granularity/expressiveness offer some extra
functionality in some cases or is it a matter of style?

IIRC, it's important for functions returning composite types. For a
function returning scalar, "AS a" is equivalent to "AS a(a)".

regards, tom lane