Non-Materialized CTE bug?

From: greigwise <greigwise(at)comcast(dot)net>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Non-Materialized CTE bug?
Date: 2020-10-28 00:43:08
Message-ID: 1603845788861-0.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

create table types (type varchar);
CREATE TABLE
insert into types values ('a');

with test (i, j) as
(values ( 1, '{"key": "a", "value": "true"}'::json), (2, '{"key": "b",
"value": "xxx"}'::json)),
test2 (i, j) as (select i, (j->>'value')::boolean
from test a
join types b on b.type = a.j->>'key') select * from test2 where j = true;

ERROR: invalid input syntax for type boolean: "xxx"

Why would this result in an error here? It seems like the second row from
the "test" CTE should be excluded since the key value "b" will not join with
anything in the "types" table. If I materialize the "test2" CTE, then it
works as I'd expect without error. Is this a bug? It seems like the
optimizer should be smart enough to know that it has to materialize that
CTE. This is on version 12.4.

Thanks for the help.
Greig Wise

--
Sent from: https://www.postgresql-archive.org/PostgreSQL-bugs-f2117394.html

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2020-10-28 01:58:57 BUG #16688: psql removes only LF without CR at end of backquotes on windows.
Previous Message Tom Lane 2020-10-27 23:38:08 Re: BUG #16671: "generated always as" is ignored when updating table through view