agora inbox for pgsql-bugs@postgresql.org
help / color / mirror / Atom feedFrom: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 1482694023@qq.com
Subject: BUG #19709: Incorrect result when comparing OLD tuple column to itself in INSERT RETURNING
Date: Sun, 20 Sep 2026 12:28:14 +0000
Message-ID: <19709-388df6818f7ef822@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19709
Logged by: N J
Email address: 1482694023@qq.com
PostgreSQL version: 18.4
Operating system: Windows 11 64-bit
Description:
Environment:
PostgreSQL: 18.4
OS: Windows 11 64-bit
Reproduction query:
CREATE TEMP TABLE IF NOT EXISTS a0 (x INTEGER);
TRUNCATE TABLE a0;
INSERT INTO a0 VALUES (42)
RETURNING
CASE
WHEN (old).x IS DISTINCT FROM old.x THEN 1
ELSE 0
END AS bug;
Observed result:
bug
-----
1
Expected result:
bug
-----
0
Explanation:
For INSERT statements, the OLD tuple is all NULL.
The expression old.x IS DISTINCT FROM old.x compares NULL with NULL.
Per SQL standard, NULL IS DISTINCT FROM NULL returns false, so the CASE
expression should return 0.
PostgreSQL incorrectly evaluates this predicate to true and returns 1.
view thread (2+ messages) latest in thread
Message-ID: <19709-388df6818f7ef822@postgresql.org>
Permalink: ../19709-388df6818f7ef822@postgresql.org/
Also on: postgresql.org/message-id/19709-388df6818f7ef822@postgresql.org
reply
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, 1482694023@qq.com
Subject: Re: BUG #19709: Incorrect result when comparing OLD tuple column to itself in INSERT RETURNING
In-Reply-To: <19709-388df6818f7ef822@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox