From: | Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> |
---|---|
To: | PG-General Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Two columns with same name in subselect--any way to SELECT without *? |
Date: | 2018-01-07 04:46:01 |
Message-ID: | CAD3a31UikwBZwLwAT-cxNDEFOvhHx2RnVT1RCUTR08mA+bpMRw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi. You can have multiple columns with the same name, and use it as a
subselect, like this silly example:
SELECT 'a' AS my_col,'b' AS my_col,'foo' AS other;
SELECT * FROM (SELECT 'a' AS my_col,'b' AS my_col,'foo' AS other) foo;
But is there any way to select either of those columns without taking all
the fields with *?
SELECT my_col,other FROM (select 'a' AS my_col,'b' AS my_col,'foo' AS
other) foo;
ERROR: column reference "my_col" is ambiguous
I suspect there isn't, but just wondering if there's some way I'm not
aware of.
I found myself wanting to specify the columns by position, similar to
ORDER or GROUP. (*.1, foo.1 or something like that), but that's
probably wishful thinking!
Cheers,
Ken
--
AGENCY Software
A Free Software data system
By and for non-profits
*http://agency-software.org/ <http://agency-software.org/>*
*https://demo.agency-software.org/client
<https://demo.agency-software.org/client>*
ken(dot)tanzer(at)agency-software(dot)org
(253) 245-3801
Subscribe to the mailing list
<agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
learn more about AGENCY or
follow the discussion.
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2018-01-07 05:10:09 | Re: Two columns with same name in subselect--any way to SELECT without *? |
Previous Message | Travis Allison | 2018-01-06 20:36:34 | Re: What generates pg_config.h? |