pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUsing Aliases in Select
4+ messages / 3 participants
[nested] [flat]
* Using Aliases in Select
@ 1999-08-02 13:22 Christian Rudow <Christian.Rudow@thinx.ch>
1999-08-02 13:39 ` Re: [SQL] Using Aliases in Select Andy Lewis <alewis@themecca.net>
1999-08-02 14:06 ` Re: [SQL] Using Aliases in Select Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 4+ messages in thread
From: Christian Rudow @ 1999-08-02 13:22 UTC (permalink / raw)
To: pgsql-sql
I join 2 tables that both have a row "mytext".
I want to use both text fields in the select (projection) clause, giving
alias names to them.
select tab1.name, tab1.mytext text1, tab2.mytext text2
from tab1, tab2
where tab1.tab1_id = tab2.tab1_id
but ...
ERROR: Column 'mytext' is ambiguous
Is there a solution to this ?
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Christian Rudow E-Mail: Christian.Rudow@thinx.ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] Using Aliases in Select
1999-08-02 13:22 Using Aliases in Select Christian Rudow <Christian.Rudow@thinx.ch>
@ 1999-08-02 13:39 ` Andy Lewis <alewis@themecca.net>
1999-08-02 14:06 ` Re: [SQL] Using Aliases in Select Christian Rudow <Christian.Rudow@thinx.ch>
1 sibling, 1 reply; 4+ messages in thread
From: Andy Lewis @ 1999-08-02 13:39 UTC (permalink / raw)
To: Christian Rudow <Christian.Rudow@thinx.ch>; +Cc: pgsql-sql
I'll take a stab at this one:
Try:
select tab1.name, tab1.mytext as text1, tab2.mytext as text2
from tab1, tab2 where tab1.tab1_id = tab2.tab1_id
I believe that this will fix it.
Andy
On Mon, 2 Aug 1999, Christian Rudow wrote:
> I join 2 tables that both have a row "mytext".
> I want to use both text fields in the select (projection) clause, giving
> alias names to them.
>
> select tab1.name, tab1.mytext text1, tab2.mytext text2
> from tab1, tab2
> where tab1.tab1_id = tab2.tab1_id
>
> but ...
>
> ERROR: Column 'mytext' is ambiguous
>
> Is there a solution to this ?
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Christian Rudow E-Mail: Christian.Rudow@thinx.ch
> ThinX networked business services Stahlrain 10, CH-5200 Brugg
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] Using Aliases in Select
1999-08-02 13:22 Using Aliases in Select Christian Rudow <Christian.Rudow@thinx.ch>
1999-08-02 13:39 ` Re: [SQL] Using Aliases in Select Andy Lewis <alewis@themecca.net>
@ 1999-08-02 14:06 ` Christian Rudow <Christian.Rudow@thinx.ch>
0 siblings, 0 replies; 4+ messages in thread
From: Christian Rudow @ 1999-08-02 14:06 UTC (permalink / raw)
To: Andy Lewis <alewis@themecca.net>; +Cc: pgsql-sql
Andy Lewis wrote:
> select tab1.name, tab1.mytext as text1, tab2.mytext as text2
> from tab1, tab2 where tab1.tab1_id = tab2.tab1_id
>
> I believe that this will fix it.
>
> Andy
Yes it does.
My knowledge of SQL all comes from working with Informix databases.
ThanX a lot !
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Christian Rudow E-Mail: Christian.Rudow@thinx.ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] Using Aliases in Select
1999-08-02 13:22 Using Aliases in Select Christian Rudow <Christian.Rudow@thinx.ch>
@ 1999-08-02 14:06 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 4+ messages in thread
From: Tom Lane @ 1999-08-02 14:06 UTC (permalink / raw)
To: Christian Rudow <Christian.Rudow@thinx.ch>; +Cc: pgsql-sql
Christian Rudow <Christian.Rudow@thinx.ch> writes:
> select tab1.name, tab1.mytext text1, tab2.mytext text2
> from tab1, tab2
> where tab1.tab1_id = tab2.tab1_id
> ERROR: Column 'mytext' is ambiguous
As Oleg points out, you need to write AS text1 and so forth. The AS
is not optional when labeling output columns, even though you are
allowed to leave it out in the FROM list. But I am wondering about
the error message --- all the Postgres versions that I have say
ERROR: parser: parse error at or near "text1"
which may not be too helpful but at least it's not outright
misleading. What version are you using?
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1999-08-02 14:06 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-08-02 13:22 Using Aliases in Select Christian Rudow <Christian.Rudow@thinx.ch>
1999-08-02 13:39 ` Andy Lewis <alewis@themecca.net>
1999-08-02 14:06 ` Christian Rudow <Christian.Rudow@thinx.ch>
1999-08-02 14:06 ` Tom Lane <tgl@sss.pgh.pa.us>
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