Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x8Gt8-000000014mp-1M7s for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Sep 2026 12:43:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x8Gt6-00000006Y4C-0wrp for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Sep 2026 12:43:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x8GfN-00000006XpV-0rij for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 12:29:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x8GfK-00000000KTf-11xP for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 12:29:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=MaHCQithi0IRMKO0S+1uX7PsnYkORdedvbhXsxwvmns=; b=fJK05AhsthokhLa6DY6vNORdpX Js3EOoH1AGbHCEAsY8heWkPM6cGZT1ovElhOOYtp46pE2YP23BvSTCJIVRXw/ioMhl65nstgK4xHx AjEQ2mlTnf7RPdc2xncmBuBYgLXKoyQEAaB2St9R6UFEufHO4CTJhEtCj0VnPi47OM2wNU0T7Os54 l5wb8a3L87dPs2gNIrCPIg1dubPko3pesgFwcgk8FMidVYKHvaNmhU/NDk6O//7dFnvae9MpJxCX4 tI5+ogH1rjwqIizKHtw8j9LlmIDs7AB2QBfJQW6UoFtZijdfJJHO7Rw0oBDBfo0lyZi0F3kmyf7Wg k/10kwhg==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x8GfI-00109X-18 for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 12:29:06 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x8GfG-00000002pRG-2wYz for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 12:29:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19709: Incorrect result when comparing OLD tuple column to itself in INSERT RETURNING To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 1482694023@qq.com Reply-To: 1482694023@qq.com, pgsql-bugs@lists.postgresql.org Date: Sun, 20 Sep 2026 12:28:14 +0000 Message-ID: <19709-388df6818f7ef822@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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: =20 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.