From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: [Q] Table aliasing |
Date: | 2013-10-04 13:11:31 |
Message-ID: | 1380892291029-5773364.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Ladislav Lenart wrote
> * Should I alias one of the references to deal?
> * The above query works the same both with and without an alias, so is it
> simply
> a matter of taste / good practice?
> * Where can I find more info about this, i.e. when the alias is mandatory
> and
> when it is only a convenience? I've scanned through
>
>
> http://www.postgresql.org/docs/9.1/static/queries-table-expressions.html
>
> but it only mentions that subselect in FROM must have an alias. I would
> like to
> know about IN (...) and EXISTS (...).
Aliases are mandatory for self-joins. Basically two relations at the same
query level cannot have the same name. With sub-selects the inner level
shields the outer level from being visible so an alias is optional. I
believe the case of a correlated sub-query requires the alias for the same
reason - otherwise you end up with a always true where clause when joining
the supposed two deal tables together.
There is no right/best way but it is always more clear to rename such that
you avoid repeating the same relation name in the query.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Q-Table-aliasing-tp5773355p5773364.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Ladislav Lenart | 2013-10-04 13:51:44 | Re: [Q] Table aliasing |
Previous Message | Adam Jelinek | 2013-10-04 12:46:39 | Re: [Q] Table aliasing |