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 1w02D6-001Y4e-1u for pgsql-general@arkaria.postgresql.org; Tue, 10 Mar 2026 18:53:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w02D0-005KSb-2q for pgsql-general@arkaria.postgresql.org; Tue, 10 Mar 2026 18:53:35 +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 1w02D0-005KSS-1p for pgsql-general@lists.postgresql.org; Tue, 10 Mar 2026 18:53:35 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w02Cy-000000020pR-2HC8 for pgsql-general@lists.postgresql.org; Tue, 10 Mar 2026 18:53:34 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-439b9b1900bso7056299f8f.1 for ; Tue, 10 Mar 2026 11:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773168811; x=1773773611; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=C1/majpXnygWfvM0ytztS3Pro8Q9x69BiLWuPUB77zg=; b=DMGYEU38lxEtPAqkc/IT3rIdJ9RMFYp4ISd2DqOSDbJxIM0i6JIKazptnCmMEK0p7U WDTF1AWtl3ngYtrfuy+rTTrumEP2dMCVoRBgkZ3HxXLbpFqZXMqHaWLlVBGwVfSlth+3 2G/E4hq7dg0WWRJHFdR34j4AoitGBL+lR9sZxPhlYMh8iCxLEL2Ip+8ngKAmvRetKtLG Or/Bt78nLH/qw7C4pKeUBC8cWrfzLitNpzbCVzQovrqVNOKpjWBpoRzjrH5ONuiGDe8f jAcUjak52NHBwC/psmaG0LCTjlDiiBglMo0lGnYFlLRnGpAQ6SMCyVu2l2YGCVoyC3B/ Ow2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773168811; x=1773773611; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=C1/majpXnygWfvM0ytztS3Pro8Q9x69BiLWuPUB77zg=; b=R5HhfRSUep0NNRhzCXyhx3lMoarlnOvv0NPef75mbQGIBio3/WaAJ8IBBVWkBHb6wc /8nfF9v7xgRJhk2YDlrN/Lkbn8h4PTiLxMMHD8XmbB0LY0LIIj9yXYx7k6JNr4KGHWFf kyLH1xs3wAxnAupP8d77wFrAU0jbck8ZVVikibF1i/KA7ERL4uGoxDrRXUKXlhk9ZvqK ekN19qHme5Ddtk1LHLgvtBrRifiGJLjpCb3SeKl14on0zvDJjfHH9PBp+YBERbdw69Dg TqhTa7RXjkAXueTvp+YY1nvOOUTPzkFTPtsp7/WuVdSBiBI2iBUcFSMqiODFeNudQgTy /rZA== X-Gm-Message-State: AOJu0Yy1J0hZNsgTCbYMifOpd/HAJWx4/zBviF+JCuu1NLHHNAPS6qST 532TrqCAmNinMqwLoZc6ZT1Xzqobbz35S1p9Qknr7WJT+4pWRQZvt2fp X-Gm-Gg: ATEYQzzFpNhxJ/nVLr7TO7NGMZLAWI7QdxzzpZ6jxhGT3LfRoIqDyTRZ9uzwYL7Utiy yfRNvVwP5Jv7sPI3yKXfYb27wpqVoJOpfGVPg5ksPDc+pkWkdn9dldmr6qaT0PcmqNJQpWK/XtE bc+zLD5tNkP3H3eycT3Ggvp6l0aIb67n2PdFMF+uF+frTU8VoGxzCw41zUzTsTb0pAOUJNxsYUw krxTHNJ5PpOWV5RtkUNPKb+Wz1Wr4g/Jwt4Y3n7tqpOVqtN+nAwhrwhXAmQt3boThb0ZSiD5XsJ twXuMRUV0zBDPdRgf9D5Lp3dbkXHFR6InnvqNm4OfR0bhjHXsNruyXMfRzG7y+qdXyfPv3Qeaej 7sxEM5UCtHlprig++6+7U6oY5yo4u5jF+sndD12kI0GyTkCTzJ0R++MQJWkTwcePuZwY7l+P+gF 7A7Lztf0F9nCcGxryVxx7s5vMJF39B0BVjNYV2XkPqd6qhLpS5pEsz8b8cdZzqodzPRodbZIcXA Q== X-Received: by 2002:a05:6000:2c0c:b0:439:b541:a088 with SMTP id ffacd0b85a97d-439da8a2e9fmr26873495f8f.54.1773168811113; Tue, 10 Mar 2026 11:53:31 -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 ffacd0b85a97d-439f81a0239sm10685f8f.10.2026.03.10.11.53.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Mar 2026 11:53:30 -0700 (PDT) Message-ID: Date: Tue, 10 Mar 2026 19:53:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?UTF-8?Q?Re=3A_LISTAGG_=C3=A0_la_Oracle_in_PostgreSQL?= To: Paul A Jungwirth Cc: "pgsql-general@lists.postgresql.org" References: Content-Language: en-US From: Pierre Forstmann 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 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; >