[GENERAL] why isn't this subquery wrong?
От | jonathan vanasco |
---|---|
Тема | [GENERAL] why isn't this subquery wrong? |
Дата | |
Msg-id | 0B9030D9-7B8A-4921-9453-D0E3C6254818@2xlp.com обсуждение исходный текст |
Ответы |
Re: [GENERAL] why isn't this subquery wrong?
Re: [GENERAL] why isn't this subquery wrong? Re: [GENERAL] why isn't this subquery wrong? Re: [GENERAL] why isn't this subquery wrong? |
Список | pgsql-general |
I ran into an issue while changing a database schema around. Some queries still worked, even though I didn't expect them to.
Can anyone explain to me why the following is valid (running 9.6) ?
schema
CREATE TEMPORARY TABLE example_a__data (foo_id INT,bar_id INT);CREATE TEMPORARY TABLE example_a__rollup_source (id int primary key,name varchar(64),foo_id INT,check_bool BOOLEAN);CREATE TEMPORARY TABLE example_a__rollup ASSELECT id, name, foo_idFROM example_a__rollup_sourceWHERE check_bool IS TRUE;
SELECT foo_idFROM example_a__dataWHERE foo_id IN (SELECT bar_id FROM example_a__rollup);
a raw select of `SELECT bar_id FROM example_a__rollup;` will cause an error because bar_id doesn't exist
postgres doesn't raise an error because example_a__data does have a bar_id -- but example_a__rollup doesn't and there's no explicit correlation in the query.
can someone explain why this happens? i'm guessing there is a good reason -- but I'm unfamiliar with the type of implicit join/queries this behavior is enabling.
В списке pgsql-general по дате отправления: