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

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: eatkin(at)certusllc(dot)us, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18430: syntax error when using aggregate function in where clause of subquery
Date: 2024-04-12 17:44:59
Message-ID: cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Eric Atkin 2024-04-12 18:35:46 Re: BUG #18430: syntax error when using aggregate function in where clause of subquery
Previous Message PG Bug reporting form 2024-04-12 17:14:31 BUG #18430: syntax error when using aggregate function in where clause of subquery