Re: Why does this SQL work?

From: Anil Menon <gakmenon(at)gmail(dot)com>
To: Victor Yegorov <vyegorov(at)gmail(dot)com>, hubert depesz lubaczewski <depesz(at)depesz(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why does this SQL work?
Date: 2015-05-12 08:07:52
Message-ID: CAHzbRKdZKhLTJx3jjwT4y=CBxfm7wB3NdDG6wD_RXedhv2U7KQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you very much - looks like I will have to prefix all cols.

Regards
AK

On Tue, May 12, 2015 at 3:05 AM, Victor Yegorov <vyegorov(at)gmail(dot)com> wrote:

> 2015-05-11 19:26 GMT+03:00 Anil Menon <gakmenon(at)gmail(dot)com>:
>
>> manualscan=> select count(*) From public.msgtxt where msgid in (select
>> msgid From ver736.courier where org_id=3);
>> count
>> -------
>> 10225
>> (1 row)
>>
>> Please note, there is no msgid col in courier table. Which brings the
>> question why does this SQL work? An "select msgid From courier where
>> org_id=3" by itself gives error column "msgid" does not exist.
>>
>
> Because you can reference both, inner and outer columns from the inner
> query.
> Here you're most likely referring to the outer `msgid` in the subquery.
>
> That's why it is always a good idea to prefix all your columns with tables
> aliases.
>
>
> --
> Victor Y. Yegorov
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2015-05-12 08:19:22 Re: [BDR] Node Join Question
Previous Message Peter Mogensen 2015-05-12 07:40:16 Re: Comparing txid and xmin (under BDR)