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.