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 1w0K2a-001oHj-2M for pgsql-general@arkaria.postgresql.org; Wed, 11 Mar 2026 13:56:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0K2Y-009K5q-0H for pgsql-general@arkaria.postgresql.org; Wed, 11 Mar 2026 13:55:58 +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.96) (envelope-from ) id 1w0K2X-009K5i-1B for pgsql-general@lists.postgresql.org; Wed, 11 Mar 2026 13:55:58 +0000 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w0K2V-00000001cJ5-3hO7 for pgsql-general@lists.postgresql.org; Wed, 11 Mar 2026 13:55:56 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 7ED087A00AC; Wed, 11 Mar 2026 09:55:55 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Wed, 11 Mar 2026 09:55:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1773237355; x=1773323755; bh=ISJ/hk+z9WaJX9XIg66K1vHBu0WpeoMl3Sad9pSRNHQ=; b= aWJ4X5HL55HPsfXhyhOQs7HtBM2G/Snm9U7OEbuhChVUvXmDmCeDJHQngqK6DoMS C/VhhZhmPFzPt4DxyrLK1iFMFVM9RyIBCsj8ec2yQ8dhphZLjyljmGc1AZPsCInS M4kIqQFvStnTXMZmDlOHXmdTbTok0s8wKpeohWVs/LlEt8Jmjsvfz7RHivUPY18Y 0oGkh0dWeA0bQeWYDPtXIhDh7jzhWtoOt/WxZVBiwITLw0Qc1NQ5ckYGQ2PY31tT Sn8qpYbRgKtzD13QmG3qnbNsK3ShRvJ7ajOW7BJOINaqgLup36gW9+8ohDKRb9lg oDssyx5ThNh6sEi/FhO+IQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1773237355; x=1773323755; bh=I SJ/hk+z9WaJX9XIg66K1vHBu0WpeoMl3Sad9pSRNHQ=; b=16dF3JW/n5iBnU76Z p9DaW0SVL6YhzTzSDwolf8v2D7FFEPsvXdFs/IW3YpYTkvts/dgX3Cfy5ZZ4aDjK NV8uf/2vbB1ZQQ3CB9IIixp/wvdUwgL3CEZ/kZTaEjQdzR7idqAvREnyFqlvMRpJ jkGa8HAfHqsOeqnE8Yc4KB1sXW1jh9IwNM30jncBPetzB1utC0XIk1YhISYzLvrQ EkWGMFhvV3yQCCHbZliykse6z6R0gegosphD4nPR9AIbq6q/nOop2maaDaaKKZac NMQF4CbjZTmp43I7nYLMNDj4PVK/6mlg6HQYhzxo2fR8L1YmtTvv+GNsRgzyz0/7 kXcqA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeegtdekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheprfgvthgvrhcu gfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgqeenuc ggtffrrghtthgvrhhnpedugfejffefleefvdegvdejvdeiheevgffhjefgudfhvedvjeev feehteelgfevfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehpvghtvghrsegvihhsvghnthhrrghuthdrohhrghdpnhgspghrtghpthhtohep vddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphhivghrrhgvrdhfohhrshhtmh grnhhnsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlhes lhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 11 Mar 2026 09:55:54 -0400 (EDT) Message-ID: <7d03be7f-9d20-4285-9342-af1d51435b5a@eisentraut.org> Date: Wed, 11 Mar 2026 14:55:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?UTF-8?Q?Re=3A_LISTAGG_=C3=A0_la_Oracle_in_PostgreSQL?= To: Pierre Forstmann , "pgsql-general@lists.postgresql.org" References: Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 09.03.26 21:21, Pierre Forstmann wrote: > Hello, > > I can write a LISTAGG aggregate for: > > create table emp(deptno numeric, ename text); > > SELECT deptno, LISTAGG(ename, ','::text ORDER BY ename) AS employees > FROM   emp GROUP BY deptno ORDER BY deptno; > > I would like to know if is possible to create an aggregate LISTAGG that > would work like in Oracle: > > SELECT deptno, >        listagg(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees > FROM emp > GROUP BY deptno > ORDER BY deptno; > > I failed and IA also failed. Claude says: > > It is not possible to exactly replicate listagg(ename, ',') WITHIN GROUP > (ORDER BY ename) as a custom PostgreSQL aggregate > because PostgreSQL strictly forbids ungrouped columns as direct > arguments to ordered-set aggregates. > > Do you agree ? One of the reasons that PostgreSQL hasn't implemented LISTAGG is that it is a misdesign. It uses ordered-set aggregate syntax even though it is not very similar to the other ordered-set aggregates. Its syntax should be more similar to ARRAY_AGG or JSON_ARRAYAGG, for example. But it's too late to fix the standard on this.