Broken type checking for empty subqueries

From: Marek Malevič <marek(at)malevicovi(dot)net>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Broken type checking for empty subqueries
Date: 2023-09-28 09:08:15
Message-ID: 7e55db68-7169-4e43-363e-947c79ba7922@malevicovi.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,

after upgrade from PG11 to PG14.8 the following statement started failing:

select
    a::BIGINT
FROM (
    SELECT
        '$maybeNumber'::VARCHAR AS a
    WHERE NOT '$maybeNumber' LIKE '%maybeNumber'
) AS foo;

Expected (as in PG11): The query should return empty result with one column.
Actual:  SQL Error [22P02]: ERROR: invalid input syntax for type bigint:
"$maybeNumber".

Where is a workaround that shows the behavior is quite non-stable.
Following passes normally while still using the same subquery with one
more empty result from another one:

select
    a::BIGINT
FROM (
    SELECT
        '$maybeNumber'::VARCHAR AS a
    WHERE NOT '$maybeNumber' LIKE '%maybeNumber'
    UNION
    SELECT '0' AS a WHERE false
) AS foo;

Thanks all for the great work you do on PG.
Marek Malevic

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2023-09-28 10:33:14 Re: Missed TidRangePath in the print_path switch
Previous Message Alexander Lakhin 2023-09-28 08:00:00 Re: BUG #18135: Incorrect memory access occurs when attaching a partition with an index