PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16368
PG Version12.2
OSGentoo Linux
Opened2020-04-15 17:50:46+00
Reported byElvis Pranskevichus
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16368
Logged by:          Elvis Pranskevichus
Email address:      (redacted)
PostgreSQL version: 12.2
Operating system:   Gentoo Linux
Description:        

Consider the following function:

CREATE OR REPLACE FUNCTION intfmt(input text, fmt text)
 RETURNS bigint
 LANGUAGE sql
AS $$ 
SELECT 
  CASE WHEN fmt IS NULL 
    THEN input::bigint 
    ELSE to_number(input, fmt)::bigint 
  END; 
$$;

And the following query:

SELECT
    intfmt('123,456', q.fmt) AS "out"
FROM
    (SELECT
            ("v" = first_value("v") OVER ()),
            '999,999' AS "fmt"
        FROM
            (SELECT 1 AS "v") AS "q2"
    ) AS "q";

The expected result is the integer 123456, but the query fails with:

ERROR:  invalid input syntax for type bigint: "123,456"
CONTEXT:  SQL function "intfmt" during inlining

Which means that somehow during inlining of "intfmt" Postgres incorrectly
takes the first branch in the `CASE` expression. This only happens in the
presence of the "first_value" window call in the nested query.

                Elvis

Messages

DateAuthorSubject
2020-04-15 17:50:46+00PG Bug reporting formBUG #16368: Incorrect function inlining in the presence of a window function
2020-04-15 18:32:54+00"David G(dot) Johnston"Re: BUG #16368: Incorrect function inlining in the presence of a window function
2020-04-15 20:08:28+00Elvis PranskevichusRe: BUG #16368: Incorrect function inlining in the presence of a window function
2020-04-15 20:21:25+00"David G(dot) Johnston"Re: BUG #16368: Incorrect function inlining in the presence of a window function
2020-04-16 00:14:05+00Tom LaneRe: BUG #16368: Incorrect function inlining in the presence of a window function
2020-04-16 01:17:30+00Elvis PranskevichusRe: BUG #16368: Incorrect function inlining in the presence of a window function
2020-04-16 02:06:39+00Elvis PranskevichusRe: BUG #16368: Incorrect function inlining in the presence of a window function
2020-04-16 09:10:49+00Kyotaro HoriguchiRe: BUG #16368: Incorrect function inlining in the presence of a window function