Re: LISTAGG à la Oracle in PostgreSQL
| От | Pierre Forstmann |
|---|---|
| Тема | Re: LISTAGG à la Oracle in PostgreSQL |
| Дата | |
| Msg-id | c5b36c72-ae87-4623-85a5-b487090923b4@gmail.com обсуждение исходный текст |
| Ответ на | Re: LISTAGG à la Oracle in PostgreSQL (Paul A Jungwirth <pj@illuminatedcomputing.com>) |
| Ответы |
Re: LISTAGG à la Oracle in PostgreSQL
|
| Список | pgsql-general |
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 > <pierre.forstmann@gmail.com> 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; >
В списке pgsql-general по дате отправления: