Re: BUG #18430: syntax error when using aggregate function in where clause of subquery

Поиск
Список
Период
Сортировка
От Laurenz Albe
Тема Re: BUG #18430: syntax error when using aggregate function in where clause of subquery
Дата
Msg-id cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at
обсуждение исходный текст
Ответ на BUG #18430: syntax error when using aggregate function in where clause of subquery  (PG Bug reporting form <noreply@postgresql.org>)
Ответы Re: BUG #18430: syntax error when using aggregate function in where clause of subquery  (Eric Atkin <eatkin@certusllc.us>)
Список pgsql-bugs
On Fri, 2024-04-12 at 17:14 +0000, PG Bug reporting form wrote:
> SELECT
>     city,
>     (SELECT count(*) FROM delivery WHERE driver_id IN array_agg(driver.id))
> AS deliveries
> FROM driver
> GROUP BY city
> ;
>
> This produces:
>
> ERROR:  syntax error at or near "array_agg"
> LINE 3: ...(SELECT count(*) FROM delivery WHERE driver_id IN array_agg(...

This not a bug, but bad syntax.

Write

  SELECT city,
         (SELECT count(*)
          FROM delivery
          WHERE driver_id = ANY (drivers)) AS deliveries
  FROM (SELECT city,
               array_agg(driver.id) AS drivers
        FROM driver
        GROUP BY city) AS q;

Yours,
Laurenz Albe



В списке pgsql-bugs по дате отправления:

Предыдущее
От: PG Bug reporting form
Дата:
Сообщение: BUG #18430: syntax error when using aggregate function in where clause of subquery
Следующее
От: Eric Atkin
Дата:
Сообщение: Re: BUG #18430: syntax error when using aggregate function in where clause of subquery