pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSELECT 1st field
6+ messages / 4 participants
[nested] [flat]
* SELECT 1st field
@ 2012-05-15 06:01 Jan Bakuwel <jan.bakuwel@greenpeace.org>
2012-05-15 06:25 ` Re: SELECT 1st field msi77 <msi77@yandex.ru>
2012-05-15 11:01 ` Re: SELECT 1st field Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 6+ messages in thread
From: Jan Bakuwel @ 2012-05-15 06:01 UTC (permalink / raw)
To: pgsql-sql
Hi,
I've spend some time checking the documentation but haven't been able to
find what I'm looking for.
I've got a function that returns a set of integers and a view that
selects from the function.
What I need is the ability to name the column in the view, ie.
create function func(i int) returns setof integer as $$
...
...code
...
$$ language plpythonu volatile;
create view v as select 1 as "id" from func(5);
In other words I'd like to refer to the first (and only) field returned
and give that an alias, in this case "id".
In some SQL dialects you can use "select 1" to select the first field,
"select 2" to select the 2nd field and so on.
Any suggestions?
regards,
Jan
Attachments:
[application/pkcs7-signature] smime.p7s (3.6K, ../../4FB1F13E.80302@greenpeace.org/2-smime.p7s)
download
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: SELECT 1st field
2012-05-15 06:01 SELECT 1st field Jan Bakuwel <jan.bakuwel@greenpeace.org>
@ 2012-05-15 06:25 ` msi77 <msi77@yandex.ru>
1 sibling, 0 replies; 6+ messages in thread
From: msi77 @ 2012-05-15 06:25 UTC (permalink / raw)
To: Jan Bakuwel <jan.bakuwel@greenpeace.org>; +Cc: pgsql-sql
Try this
create view v(id) as select * from func(5);
if your function returns one column.
15.05.2012, 10:01, "Jan Bakuwel" <jan.bakuwel@greenpeace.org>:
> Hi,
>
> I've spend some time checking the documentation but haven't been able to
> find what I'm looking for.
> I've got a function that returns a set of integers and a view that
> selects from the function.
> What I need is the ability to name the column in the view, ie.
>
> create function func(i int) returns setof integer as $$
> ...
> ...code
> ...
> $$ language plpythonu volatile;
>
> create view v as select 1 as "id" from func(5);
>
> In other words I'd like to refer to the first (and only) field returned
> and give that an alias, in this case "id".
>
> In some SQL dialects you can use "select 1" to select the first field,
> "select 2" to select the 2nd field and so on.
>
> Any suggestions?
>
> regards,
> Jan
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: SELECT 1st field
2012-05-15 06:01 SELECT 1st field Jan Bakuwel <jan.bakuwel@greenpeace.org>
@ 2012-05-15 11:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-05-15 12:21 ` Re: SELECT 1st field Misa Simic <misa.simic@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Tom Lane @ 2012-05-15 11:01 UTC (permalink / raw)
To: Jan Bakuwel <jan.bakuwel@greenpeace.org>; +Cc: pgsql-sql
Jan Bakuwel <jan.bakuwel@greenpeace.org> writes:
> What I need is the ability to name the column in the view, ie.
> create view v as select 1 as "id" from func(5);
I think what you're looking for is the ability to re-alias a column name,
for example
select id from func(5) as foo(id);
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: SELECT 1st field
2012-05-15 06:01 SELECT 1st field Jan Bakuwel <jan.bakuwel@greenpeace.org>
2012-05-15 11:01 ` Re: SELECT 1st field Tom Lane <tgl@sss.pgh.pa.us>
@ 2012-05-15 12:21 ` Misa Simic <misa.simic@gmail.com>
2012-05-15 23:30 ` Re: SELECT 1st field Jan Bakuwel <jan.bakuwel@greenpeace.org>
0 siblings, 1 reply; 6+ messages in thread
From: Misa Simic @ 2012-05-15 12:21 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Jan Bakuwel <jan.bakuwel@greenpeace.org>; pgsql-sql
Both works fine:
SELECT generate_series AS id FROM generate_series(1,5);
and
SELECT id FROM generate_series(1,5) AS foo(id);
Technically dont know is there any differenece...
Thanks,
Misa
2012/5/15 Tom Lane <tgl@sss.pgh.pa.us>
> Jan Bakuwel <jan.bakuwel@greenpeace.org> writes:
> > What I need is the ability to name the column in the view, ie.
>
> > create view v as select 1 as "id" from func(5);
>
> I think what you're looking for is the ability to re-alias a column name,
> for example
>
> select id from func(5) as foo(id);
>
> regards, tom lane
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: SELECT 1st field
2012-05-15 06:01 SELECT 1st field Jan Bakuwel <jan.bakuwel@greenpeace.org>
2012-05-15 11:01 ` Re: SELECT 1st field Tom Lane <tgl@sss.pgh.pa.us>
2012-05-15 12:21 ` Re: SELECT 1st field Misa Simic <misa.simic@gmail.com>
@ 2012-05-15 23:30 ` Jan Bakuwel <jan.bakuwel@greenpeace.org>
0 siblings, 0 replies; 6+ messages in thread
From: Jan Bakuwel @ 2012-05-15 23:30 UTC (permalink / raw)
To: pgsql-sql
Hi Misa, Tom & msi77,
On 16/05/12 00:21, Misa Simic wrote:
> SELECT id FROM generate_series(1,5) AS foo(id);
Thanks for the suggestions - all sorted!
cheers,
Jan
Attachments:
[application/pkcs7-signature] smime.p7s (3.6K, ../../4FB2E71A.1050104@greenpeace.org/2-smime.p7s)
download
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: SELECT 1st field
@ 2012-05-15 08:06 Misa Simic <misa.simic@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Misa Simic @ 2012-05-15 08:06 UTC (permalink / raw)
To: Jan Bakuwel <jan.bakuwel@greenpeace.org>; pgsql-sql
When you select from function I think column name is the same as
function name. So if function name is func query would be:
SELECT func AS id FROM func(5);
Sent from my Windows Phone
From: Jan Bakuwel
Sent: 15/05/2012 08:02
To: pgsql-sql@postgresql.org
Subject: [SQL] SELECT 1st field
Hi,
I've spend some time checking the documentation but haven't been able to
find what I'm looking for.
I've got a function that returns a set of integers and a view that
selects from the function.
What I need is the ability to name the column in the view, ie.
create function func(i int) returns setof integer as $$
...
...code
...
$$ language plpythonu volatile;
create view v as select 1 as "id" from func(5);
In other words I'd like to refer to the first (and only) field returned
and give that an alias, in this case "id".
In some SQL dialects you can use "select 1" to select the first field,
"select 2" to select the 2nd field and so on.
Any suggestions?
regards,
Jan
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2012-05-15 23:30 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-05-15 06:01 SELECT 1st field Jan Bakuwel <jan.bakuwel@greenpeace.org>
2012-05-15 06:25 ` msi77 <msi77@yandex.ru>
2012-05-15 11:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-05-15 12:21 ` Misa Simic <misa.simic@gmail.com>
2012-05-15 23:30 ` Jan Bakuwel <jan.bakuwel@greenpeace.org>
2012-05-15 08:06 Re: SELECT 1st field Misa Simic <misa.simic@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox