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 1vzh6t-001EGY-2y for pgsql-general@arkaria.postgresql.org; Mon, 09 Mar 2026 20:21:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzh6s-000jRR-0h for pgsql-general@arkaria.postgresql.org; Mon, 09 Mar 2026 20:21:50 +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 1vzh6r-000jRJ-2Q for pgsql-general@lists.postgresql.org; Mon, 09 Mar 2026 20:21:50 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzh6p-00000001rIn-3GnG for pgsql-general@lists.postgresql.org; Mon, 09 Mar 2026 20:21:49 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-48535a0ef86so15159485e9.1 for ; Mon, 09 Mar 2026 13:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773087706; x=1773692506; darn=lists.postgresql.org; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=SYXke/xTWCybH5fK0XzSVx/WeI959D8ayk1rHzS3qNk=; b=RNesow5GEt9959GjQKm4nT5K/Zlho7EY2EcOEQTeNClHRFjqrXGtky+F5y6PkBk6CJ CT+FcG3FkmhjIm0pZCSEGcjtw+LIUk7c6tLESI1FIsGPQeSKqlxzCBbvvcZXCXPsJVTD kxtYO1N8cGRpXAKukkeybfjocIY2sjYRxqfNVZEasX1EiWIKrWTHpV3k8v/rvbnnFPEK eBNkB3X/mLucEBgOOmsgvqAOh8Nrvac8t1AYWbJXu6izOxlRBICdJyIiuLZgoK7dN6KE YWmGVR5kQ5IgA5YmOfztRFez3A9/xs9Oi5AVJqmugKTk9lcYZdXLxsB9h5zrVJ/oND9A gmlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773087706; x=1773692506; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SYXke/xTWCybH5fK0XzSVx/WeI959D8ayk1rHzS3qNk=; b=sstPHEXy8ZjS0bomCvhFP5XLLO3xJt7i4bXufM+HqvGZ+ZQxDJd/PLfr/3KhF+Vt4n Y9gYbBGJHdZxB4Uh80wXOR4+qRuyebe+3EOaAXHA1IliZs16Ltmr+Z3K/Mw7ibpadGQU c2c/SCNTIODwzInetAuAMSKkKbsVY+zEKGe5RG+VB9KYxz51Et2/CC+63yHjV8XldQ0l OaOg8pbvUEZvdiLoiI7u6RQRUOs9ypABuBLuIUej04Mrf2iq/ba/UF6Z0YRY1WO6+EVa nEuSg5fFx/yha7Bzqii8cl7r931Vz97iOt1HbcGFdsz7kRmbgdC9YchFwM/3DftPu2NS BayA== X-Gm-Message-State: AOJu0Yw2ihCwrKojA2uQMKLdzfzqUPzS68aYAiQLBUWDdosY5lT/TwXW SYnYXFO9p8P4lUPtQsJhmzrDIM+RaaJXTBLugvbue2kRHBVRqnrEbeeXx0vIZA== X-Gm-Gg: ATEYQzy7ZhtVEZL/gezPF50bKhdOqt+NR8ZyyX9Ez6pBBtZ7urQz70y1LcseqJbiO1p dUlHlBN8XLfAnc028iWWheD5EaAzIhnwKZcgMbnaUVLCobwbPSaVTX9ccwEblSwAD6q/KYAYsWY LTR7c167DqgxOikDqHzLOyaDYhcL711ia2GYXqhdr2GEIlrgPm01H/0ZBkLQVq+IQ8Ml4THOkPM nBm9MlURxKzQ651GO1TtkhBnDa6NrC01WcFFRZvO1CVYCN9rn0oRzxvs5a74m/4Zrr0o2Rn0p86 EPk/c0x/xpCpttdB5xx3iCy+vDNoFvU03mdgpk9UnH+j7L6U1MPwoMwLUl3wOI3Dg4+dPlniMRg akOLrYkxgBERO7nVuDMBbOesJe4bKOYTbS1Rvt7lJ4HPmWmrz41EKtOoDQCNznTEvfKf+9SCSrJ UqczzXVe3dvsI6vXuMzirEc9g10ArDptb8uWFAgU7NTWNi6TtQiXOb5mHQ9zIkvlD7iOj2sDlIN A== X-Received: by 2002:a05:600c:4e43:b0:485:3fd1:992c with SMTP id 5b1f17b1804b1-4853fd19a0dmr38285825e9.1.1773087705864; Mon, 09 Mar 2026 13:21:45 -0700 (PDT) Received: from ?IPV6:2a01:e0a:22d:4d0:1ac0:4dff:fe8b:a3c7? ([2a01:e0a:22d:4d0:1ac0:4dff:fe8b:a3c7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48541b7f3cdsm16883725e9.14.2026.03.09.13.21.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Mar 2026 13:21:45 -0700 (PDT) Message-ID: Date: Mon, 9 Mar 2026 21:21:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "pgsql-general@lists.postgresql.org" From: Pierre Forstmann Subject: =?UTF-8?Q?LISTAGG_=C3=A0_la_Oracle_in_PostgreSQL?= 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 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 ?