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 1xPijj-00000000rOi-1UXT for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Nov 2026 15:53:48 +0000 Received: from localhost ([127.0.0.1]:50804 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xPijj-00000003qNc-39hs for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Nov 2026 15:53:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:42274) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPNZm-00000000nZg-1jWK for pgsql-bugs@lists.postgresql.org; Fri, 06 Nov 2026 17:18:06 +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 1xPNZj-00000000aPi-3Kfd for pgsql-bugs@lists.postgresql.org; Fri, 06 Nov 2026 17:18:05 +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=hxwryevXNCtDin69lt+T1HauW5ri1B+G252fZ7lgMYY=; b=rmqKETjqMDZRtOivJEbBZcgZTx CholI0loQaebwEu1FlLCbFf+N5np7x/8r4KUK+230phkQwPp5jrzHT8c7j5lKA2DHXko9r6Ns2PcE atiR3KOn152G3h7XDuWlBYH3NFDi8HourgvirOYoRK/WL9w+VLIrRd9prsj4IJyFaKXxZ45SAKIYB /5ccJtTYgpOoAndxAeZZCqiPwR2PWS+NyHy8fiwJMydcpI0pIScmIHfQoTZv9hcfe9gdhW+sy05ya MKtY/Co/Skscq9fOOt8FpdmzXd5RMJ9liFMYkHxRnq6ekANwPW1ZCLwPu65yMFl6rn78lGOrZicyd Aqq+m8lA==; 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.98.2) (envelope-from ) id 1xPNZj-00000001avQ-3ejL for pgsql-bugs@lists.postgresql.org; Fri, 06 Nov 2026 17:18:04 +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 1xPNZi-000000043Ge-3bSW for pgsql-bugs@lists.postgresql.org; Fri, 06 Nov 2026 17:18:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19835: view with GROUP BY ROLLUP over duplicate columns changes results after dump/restore To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 125atishprak@gmail.com Reply-To: 125atishprak@gmail.com, pgsql-bugs@lists.postgresql.org Date: Fri, 06 Nov 2026 17:17:36 +0000 Message-ID: <19835-65b2938eff695dc6@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: 19835 Logged by: Atish Prakash Email address: 125atishprak@gmail.com PostgreSQL version: 19rc1 Operating system: Linux Description: =20 pg_get_viewdef() prints a grouping-set member as its expression. If an earlier output column has an equal expression, the parser binds the printed expression to that earlier column. The two columns are not interchangeable under grouping sets, so a re-created view can silently return different rows. pg_dump uses this output, so a dump and restore changes the view with no error. Reproducer CREATE TABLE t (a int); INSERT INTO t VALUES (1), (2); CREATE VIEW v AS SELECT a AS x, a AS y, count(*) AS n FROM t GROUP BY ROLLUP(1, 2); SELECT * FROM v ORDER BY 1, 2; x | y | n ---+---+--- 1 | 1 | 1 1 | | 1 2 | 2 | 1 2 | | 1 | | 2 SELECT pg_get_viewdef('v'::regclass); -- ... GROUP BY ROLLUP(a, a); After pg_dump and restore into a new database: SELECT * FROM v ORDER BY 1, 2; x | y | n 1 | 1 | 1 1 | 1 | 1 2 | 2 | 1 2 | 2 | 1 | | 2 CUBE and GROUPING SETS deparse the same way. Cause get_rule_groupingset() calls get_rule_sortgroupclause() with force_colno =3D false. The parser (findTargetlistEntrySQL99) resolves an expression to the first equal targetlist entry, so the second member's sortgroupref moves to the first column. Proposed fix print the column number for a grouping-set member when an earlier non-junk targetlist entry has an equal expression. This gives GROUP BY ROLLUP(a, 2). All regression tests pass with the patch, and a new test is included in groupingsets.sql.