From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: elprans@gmail.com
Subject: BUG #16368: Incorrect function inlining in the presence of a window function
Date: Wed, 15 Apr 2020 17:50:46 +0000
Message-ID: <16368-0dd1d5ab02a3cbc0@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 16368
Logged by: Elvis Pranskevichus
Email address: elprans@gmail.com
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, elprans@gmail.com
Subject: Re: BUG #16368: Incorrect function inlining in the presence of a window function
In-Reply-To: <16368-0dd1d5ab02a3cbc0@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox