BUG #16712: Wrong Sub-Query Record Filtering

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: bugatti2(dot)5sp(at)gmail(dot)com
Subject: BUG #16712: Wrong Sub-Query Record Filtering
Date: 2020-11-12 14:26:58
Message-ID: 16712-4cf5381d0fe6790f@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16712
Logged by: SP
Email address: bugatti2(dot)5sp(at)gmail(dot)com
PostgreSQL version: 13.0
Operating system: seems any (tested on Ubuntu 18.04 and macOS 10.15)
Description:

An unexpected result returns when running this query:

WITH data_cte(str) AS (
SELECT *
FROM (VALUES ('a')) data_tmp(str)
WHERE FALSE
)
SELECT str::INTEGER
FROM data_cte;

While empty result is expected, we get this:

ERROR: invalid input syntax for type integer: "a"

Because of these type casting error, it seems that the outer query has
access to the data_cte record!

The strange thing is that if records of data_tmp (or data_cte, it doesn't
matter) be more than one, result will be true. So, for this query:

WITH data_cte(str) AS (
SELECT *
FROM (VALUES ('1a'), ('2b')) data_tmp(str)
WHERE FALSE
)
SELECT str::INTEGER
FROM data_cte;

we get this:

substring
-----------
(0 rows)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2020-11-12 14:53:43 Re: BUG #16712: Wrong Sub-Query Record Filtering
Previous Message Erik Rijkers 2020-11-12 12:48:24 Re: Problem with extract function ?