Re: [Q] Table aliasing

From: Ladislav Lenart <lenartlad(at)volny(dot)cz>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [Q] Table aliasing
Date: 2013-10-04 13:51:44
Message-ID: 524EC7F0.1020804@volny.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4.10.2013 15:11, David Johnston wrote:
> 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.

I think I understand.

Thank you,

Ladislav Lenart

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Evan Jones 2013-10-04 16:25:58 Reasons to reorder results *within* a transaction?
Previous Message David Johnston 2013-10-04 13:11:31 Re: [Q] Table aliasing