Why does this SQL work?

From: Anil Menon <gakmenon(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Why does this SQL work?
Date: 2015-05-11 16:26:15
Message-ID: CAHzbRKc-zdxa-wtdq+ZQSRBeRkQH6f8HzBQ2WwBq0fK+79n2iw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I have the following setup :

manualscan=> set search_path=ver736,public;
SET
manualscan=> \d courier;
Table "ver736.courier"
Column | Type | Modifiers
---------------+------------------------+----------------------------------------------------------
org_id | smallint | not null default
nextval('courier_org_id_seq'::regclass)
courier_name | character varying(500) | not null
courier_code | character varying(50) |
is_valid | boolean |
universe_id | character varying(50) |
courier_image | bytea |
Indexes:
"courier_pk" PRIMARY KEY, btree (org_id)
"courier_code_un" UNIQUE CONSTRAINT, btree (courier_code)
"courier_name_un" UNIQUE CONSTRAINT, btree (courier_name)
"courier_code_idx" btree (courier_code)
Referenced by:
xxx...xxx...(a few tables)

manualscan=> \d msgtxt;
Table "public.msgtxt"
Column | Type |
Modifiers
-------------------+--------------------------+--------------------------------------------------------
msgid | integer | not null default
nextval('msgtxt_msgid_seq'::regclass)
msgval | text |
transaction_stamp | timestamp with time zone | default now()
corelationid | text |
deviverymode | integer |
destination | text |
expiration | integer |
messageid | text |
priority | integer |
redelivered | boolean |
replyto | text |
timestamp | bigint |
msgtype | text |
senderid | text |
Indexes:
"msgtxt_pkey" PRIMARY KEY, btree (msgid)
Triggers:
manual_scan_tx_tr AFTER INSERT ON msgtxt FOR EACH ROW EXECUTE PROCEDURE
process_manual_scan_tx()

manualscan=> select count(*) From msgtxt where msgid in (
manualscan(> select msgid From courier where org_id=3
manualscan(> )
manualscan-> ;
count
-------
10225
(1 row)
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.

OS Version : Centos 7
PG Version : PostgreSQL 9.4.1 on x86_64-unknown-linux-gnu, compiled by gcc
(GCC) 4.8.2 20140120 (Red Hat 4.8.2-16), 64-bit

Regards
AK

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc Mamin 2015-05-11 17:10:06 Re: Restarting DB after moving to another drive
Previous Message Daniel Begin 2015-05-11 15:30:45 Re: Restarting DB after moving to another drive