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.96) (envelope-from ) id 1wcIWr-003FAR-0x for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2026 08:00:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcIWp-00G5kG-2o for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2026 08:00:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcHvA-00FomX-31 for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 07:21:17 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wcHv6-000000023ou-2OuG for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 07:21:16 +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=fG3jrKWMMFpH4FthqnB8hov3DZO6vo93yXZIzdpd9L4=; b=vCAKE+X4neDBbYfM93hrou8wcA 60Ap4RCrCeZE8KaLdsbVVMoSpBzDtlEr87bHvyIGK0komnuNxo57UU9u2Q6YaTivpDNRMeQ0DzYHV wxgHP7WZP1DcahBunyFBxjQuYWGdiODFYBvZHYtOY+Ep69tkYziXWyurzEZqKY6xY0/tTq0ecFNFH pcmQ98me1thchSQcuC2/ZBJCT5Jy3d7p8EH5R7X80zsLnVk5vBLJH0z9oyQ7oV/36Y1H/IRNVrvO1 Ihlw249JoQ77sHrmXXZ5rgWb6Tmi0Ov+55NcudAfSgU9GmQUd/gxImH84EKPG/ckc0shR4LcPpc+n iCtby5kA==; 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 1wcHv2-005kxf-1k for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 07:21:10 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcHuw-00DUsA-23 for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 07:21:02 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19531: Inconsistent Error Messages for the Same SQL Query To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 1804981203@qq.com Reply-To: 1804981203@qq.com, pgsql-bugs@lists.postgresql.org Date: Wed, 24 Jun 2026 07:20:28 +0000 Message-ID: <19531-f13c547b30872910@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: 19531 Logged by: Wang Hao Email address: 1804981203@qq.com PostgreSQL version: 18.4 Operating system: Ubuntu22.04 Description: =20 Inconsistent Error Messages for the Same SQL Query in PostgreSQL Environment=EF=BC=9A - PostgreSQL version: 18.4 - Operating System: Ubuntu 22.04 Context=EF=BC=9A My application relies on the error messages returned by SQL statement execution to perform subsequent operations. During development, I discovered that the same SQL query can return different error messages . I'm not sure if this is a bug, but it does affect my application's ability to reliably handle errors. Steps to Reproduce: Example 1: Triggering different errors by controlling the execution plan test=3D# CREATE TABLE t (c1 text DEFAULT '', c2 smallint DEFAULT 0); CREATE TABLE test=3D# INSERT INTO t (c1, c2) VALUES ('jkwdot0re', 0); INSERT 0 1 test=3D# INSERT INTO t (c1, c2) VALUES ('', -1000); INSERT 0 1 test=3D# SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP BY c1, c2; ERROR: division by zero test=3D# explain(verbose) SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP = BY c1, c2; QUERY PLAN ------------------------------------------------------------------- HashAggregate (cost=3D29.65..32.65 rows=3D200 width=3D38) Output: (c2 / c2), (c2 * c2), c1, c2 Group Key: t.c1, t.c2 -> Seq Scan on public.t (cost=3D0.00..23.10 rows=3D1310 width=3D34) Output: c1, c2 (5 rows) test=3D# SET enable_hashagg =3D off; SET test=3D# SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP BY c1, c2; ERROR: smallint out of range test=3D# explain(verbose) SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP = BY c1, c2; QUERY PLAN ------------------------------------------------------------------------- Group (cost=3D90.93..101.75 rows=3D200 width=3D38) Output: (c2 / c2), (c2 * c2), c1, c2 Group Key: t.c1, t.c2 -> Sort (cost=3D90.93..94.20 rows=3D1310 width=3D34) Output: c1, c2 Sort Key: t.c1, t.c2 -> Seq Scan on public.t (cost=3D0.00..23.10 rows=3D1310 width=3D= 34) Output: c1, c2 (8 rows) Example 2:Triggering different errors due to statistics changes test=3D# CREATE TABLE t (c1 text DEFAULT '', c2 smallint DEFAULT 0); CREATE TABLE test=3D# INSERT INTO t (c1, c2) VALUES ('jkwdot0re', 0); INSERT 0 1 test=3D# INSERT INTO t (c1, c2) VALUES ('', -1000); INSERT 0 1 test=3D# SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP BY c1, c2; ERROR: division by zero test=3D# explain(verbose) SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP = BY c1, c2; QUERY PLAN ------------------------------------------------------------------- HashAggregate (cost=3D29.65..32.65 rows=3D200 width=3D38) Output: (c2 / c2), (c2 * c2), c1, c2 Group Key: t.c1, t.c2 -> Seq Scan on public.t (cost=3D0.00..23.10 rows=3D1310 width=3D34) Output: c1, c2 (5 rows) test=3D# ANALYZE t; ANALYZE test=3D# SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP BY c1, c2; ERROR: smallint out of range test=3D# explain(verbose) SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP = BY c1, c2; QUERY PLAN -------------------------------------------------------------------- Group (cost=3D1.03..1.05 rows=3D2 width=3D11) Output: (c2 / c2), (c2 * c2), c1, c2 Group Key: t.c1, t.c2 -> Sort (cost=3D1.03..1.03 rows=3D2 width=3D7) Output: c1, c2 Sort Key: t.c1, t.c2 -> Seq Scan on public.t (cost=3D0.00..1.02 rows=3D2 width=3D7) Output: c1, c2 (8 rows) Observation: The same SQL query SELECT c2 / c2 AS e0, c2 * c2 AS e1 FROM t GROUP BY c1, c2; executed against the same data returns two different error messages: - ERROR: division by zero - ERROR: smallint out of range The query contains two expressions that can each trigger an error on the same data: - c2 / c2: division by zero when c2 =3D 0 - c2 * c2: smallint overflow when c2 =3D -1000 (since (-1000)=C2=B2 =3D 1,0= 00,000 exceeds the smallint range) In Example 1, changing enable_hashagg switches the execution plan from HashAggregate to Group.In Example 2, running ANALYZE updates table statistics I'm not certain whether this qualifies as a bug, but it does create a real problem for applications that depend on consistent error reporting from the database.Thanks for reading my report!