Issue with json_agg() and ordering

From: Bob Jones <r(dot)a(dot)n(dot)d(dot)o(dot)m(dot)d(dot)e(dot)v(dot)4+postgres(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Issue with json_agg() and ordering
Date: 2017-09-01 08:11:45
Message-ID: CA+HuS5FgxoffWJ8pp4iPySZcaopQ24MGqtqAdyMwdVm7urxhtQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Could anyone give me a few pointers as to how I might resolve the following :

select json_agg(my_table) from (my_table) where foo='test' and bar='f'
order by last_name asc, first_name asc;

ERROR: column "my_table.last_name" must appear in the GROUP BY clause
or be used in an aggregate function
LINE 1: ...foo='f' order by last_name ...

I suspect It doesn't really matter what my table looks like for the
purposes of the above, but if you need something to go by:

create table my_table(
last_name text,
first name text,
foo text,
bar boolean
);

Thanks !

Bob

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2017-09-01 08:29:51 pglogical bidirectional replication of sequences
Previous Message scott ribe 2017-09-01 03:49:30 Re: RemoveIPC problem