Re: [NOVICE] what does t(x) in select x from generate_series(1, 10) as t(x) stand for?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [NOVICE] what does t(x) in select x from generate_series(1, 10) as t(x) stand for?
Дата
Msg-id 13172.1510199779@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [NOVICE] what does t(x) in select x from generate_series(1, 10)as t(x) stand for?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-novice
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Wednesday, November 8, 2017, john snow <ofbizfanster@gmail.com> wrote:
>> is
>> select x from generate_series(1, 10) as t(x);
>> different from
>> select x from generate_series(1, 10) as x;

> Not sure about the pgAdmin part but t(x) means that you are aliasing the
> table result of the generate_series call to the name "t" and that
> tables' first (and in this case only) column is aliased to the name "x".

Right.

>   The x in the select is then that first column.  In the "as x" variant all
> you've done is alias the table to the name "x" and the "x" in the select
> refers to the table.  Not able to confirm right now but the first result
> should yield a column of type bigint while the second should a composite
> whose only column is a bigint and whose name is "generate_series".

Not sure offhand what happens for a function-returning-composite, but
I'm pretty sure that if the function returns a scalar type, then
SELECT ... from f(...) as x;

is treated the same as
SELECT ... from f(...) as x(x);

Experimentally, these all produce identical results:

select x from generate_series(1, 10) as x;
select x.x from generate_series(1, 10) as x;
select x.* from generate_series(1, 10) as x;

which seems to confirm that.
        regards, tom lane


-- 
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

В списке pgsql-novice по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: [NOVICE] what does t(x) in select x from generate_series(1, 10)as t(x) stand for?
Следующее
От: john snow
Дата:
Сообщение: [NOVICE] varchar vs varchar(n)