BUG #16653: Regression in CTE evaluation - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #16653: Regression in CTE evaluation
Date
Msg-id 16653-3154c42c219f8693@postgresql.org
Whole thread Raw
Responses Re: BUG #16653: Regression in CTE evaluation  (Bruce Momjian <bruce@momjian.us>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      16653
Logged by:          Yuri Cherio
Email address:      cherio@gmail.com
PostgreSQL version: 13.0
Operating system:   Ubuntu Linux 20.04
Description:

The following SQL worked in versions 9 through 12. It is throwing an error
in version 13.

CREATE TABLE test AS SELECT now() AS tstmp, 'value' AS val;

WITH exp_days AS (
    SELECT ''::TEXT AS days WHERE '' ~ E'^[-]?\\d+$'
)
SELECT test.*
FROM test
    CROSS JOIN exp_days
WHERE tstmp > date(current_date - CAST(exp_days.days || ' days' AS
interval));

I'd leave alone why this SQL looks ridiculous - it is a very, very
simplified case of more complex dynamic query. Statement "exp_days" returns
no rows and in previous versions the optimizer would not even try evaluating
WHERE in the final query. It doesn't seem to be the case starting version
13.


pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #16652: SELECT pg_reload_conf(); returning true despite loading config has failed
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #16653: Regression in CTE evaluation