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 1w0Lsk-001puy-0E for pgsql-general@arkaria.postgresql.org; Wed, 11 Mar 2026 15:53:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0Lsi-009xJ9-1f for pgsql-general@arkaria.postgresql.org; Wed, 11 Mar 2026 15:53:57 +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 1w0Lsi-009xJ0-0f for pgsql-general@lists.postgresql.org; Wed, 11 Mar 2026 15:53:56 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0Lsg-000000029tB-1IyA for pgsql-general@lists.postgresql.org; Wed, 11 Mar 2026 15:53:56 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4852c9b4158so91735e9.0 for ; Wed, 11 Mar 2026 08:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773244434; x=1773849234; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:references:subject:to:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=/s9ONTSYfy4Y7hqOZIpNC52xE573zow8hs/wZ8Uq8NI=; b=K7RiW0FLFs+egoe8WqpRwFlVrObOMIcBu3aYsnxC2JQ17RI12UzT7kwnkaILREJDG5 HAdTkZsCnuM+m+Lcz/e8JOJNrZdj/XYDSJJU5zEOi4k6Vtay1PNmGd24ia9gWksYcLWk 3jxd6SJnCOEKfb8c/H8NjCvvYbwGxkOnfD7YUz9cRrVRksaym1LLP6q/mH8JUAgRJtkf XuWqBUkEIAudL+nIxRM7M5Nm+Fbbno7/IC3HNBK/DfGsiGMs/QQJbb+XxaN1cq+91vEm H6+bnH3+HGp9071A2RPQyzIDHhHPwmexaidGyYSzOaiS3wwo3ZtZmomatrSV9DCyXFFt BDkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773244434; x=1773849234; h=content-transfer-encoding:in-reply-to:references:subject:to:from :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/s9ONTSYfy4Y7hqOZIpNC52xE573zow8hs/wZ8Uq8NI=; b=GLfYTJ0oNKkm7qYDMIfKGVH6q9DS4vVj13uA7LinzofD14eyajczvld+B5eJ5yAuKn muVfBRT+o5N+DAk8upcs7o1+99OBI/kzvXWQOhnbL0AiJzr7S9Sktjoe1e+Tui6Oaotz OOOGXvO47ltbpy/maKNavZaY9cCRLfoTar0h/i/KqycYaylrr0nLiM6VD60Du3EnU4Ol 1DjSZdcUGZXES4PYv8oRE3fli5aBgkryuQK+qxmthsTWfghCPj2FGuAoorH5BxKkwLqd N39CCRMVYlQ102jaYSltc1v9ljnIdbSKACdAs/7bsE2ai+uyezPy/gySuf1uNEXymII9 dfjw== X-Forwarded-Encrypted: i=1; AJvYcCVYvOmddbT5vUboaKqBsnmW7ph7kSPq9Eag+w2SdaOC1HQ9wOVri+T8MG4xb/9KbReMQxnRolic8GFDft62@lists.postgresql.org X-Gm-Message-State: AOJu0Yyv6OwkVMQ01iFhtO1r+1IVdU9WJT6eZ1m+WLfBoiD/1wEwSXnX 38rgfVztAEWJi+ekhiH1g/EqExuZFFJbNN7CW3MpaMWQApoVD9k9BidI X-Gm-Gg: ATEYQzwBNN3SvBTkMXU03GTmmqHveYFf6BYh7UT6mrkpc0Vh/z5Gon8nOhbO7oG3JJT HE/ELeFlpTIDcl7mNfFFHs6Hg4QVe8WZJhFGAx+6qdBvPTd2R1HO2OhoFjeTYsUTLwagERHhSCy kSWnMKCIBQ2K7ItXnRFundfWwEv2ViyaQiLCMI94PH+TkJpFNDcokzAitv7YJPA3kUyNeHzronL BvErDQcYMGk63Z9C0mGqxtXzXv0Aa12j7fs0nzcfN2rUP6hdonsV02MmjSFXrjuMOPxVszqmHpl HusYBuXK47ZHnFTJ0M6nV8FpvxX+V3xkQaY1vudI25h5MVrGTvMDn11Alrr1eior9v2UmAj3Asq +JCpV1Ti92XjZwxRbY6hrKx3wxcWPivGBfZAVF7ikhZSYQDna9cK2/9lJyIpnRC6cGaL6SDYNW8 mbmn/jr2ifwM7KTJe5lUvx95GVwTZvN1ZQWcdsrXvsDNYtWJ9PrYblmkHGuy3Z/muM6WdlHPBuD Q== X-Received: by 2002:a05:600c:45c3:b0:485:3e00:9440 with SMTP id 5b1f17b1804b1-4854b1396d2mr53432745e9.24.1773244433709; Wed, 11 Mar 2026 08:53:53 -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-4854b0b95f4sm34692625e9.5.2026.03.11.08.53.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Mar 2026 08:53:53 -0700 (PDT) Message-ID: Date: Wed, 11 Mar 2026 16:53:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: pierre.forstmann@gmail.com To: Pavel Stehule , Juan Rodrigo Alejandro Burgos Mella , Paul A Jungwirth , "pgsql-general@lists.postgresql.org" Subject: =?UTF-8?Q?Re=3A_LISTAGG_=C3=A0_la_Oracle_in_PostgreSQL?= References: 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 Thanks. On 10/03/2026 22:46, Pavel Stehule wrote: > > > út 10. 3. 2026 v 21:23 odesílatel Pavel Stehule > napsal: > > Hi > > út 10. 3. 2026 v 20:58 odesílatel Juan Rodrigo Alejandro Burgos > Mella > napsal: > > To do something similar, you would have to fork the source code > and implement the declarations with the same syntax, resulting > in something like Postracle. > > > orafce has listagg function https://github.com/orafce/orafce > > > > but it doesn't support syntax WITHING GROUP syntax. Probably there is > not a possibility to implement it in extension without introducing a new > kind of aggregate functions in core, or enhancing behaviour of ordered- > set kind of aggregates. > > Regards > > Pavel > > > > > > Regards > > Pavel > > > Atte > JRBM > > El mar, 10 mar 2026 a las 13:53, Pierre Forstmann > ( >) escribió: > > I agree but I just would like to know if there is way to be > compatible > with Oracle syntax using aggregate features in PostgreSQL > > Thanks. > > Le 09/03/2026 à 23:05, Paul A Jungwirth a écrit : > > On Mon, Mar 9, 2026 at 1:21 PM 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 don't think you need a custom aggregate here. In > Postgres you can say: > > > > select deptno, > >        string_agg(ename, ',' ORDER BY ename) AS employees > > FROM emp > > GROUP BY deptno > > ORDER BY deptno; > > > > >