Обсуждение: AS s(a) vs. AS a

Поиск
Список
Период
Сортировка

AS s(a) vs. AS a

От
Thalis Kalfigkopoulos
Дата:
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


Re: AS s(a) vs. AS a

От
Tom Lane
Дата:
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