Re: BUG #18430: syntax error when using aggregate function in where clause of subquery - Mailing list pgsql-bugs

From Laurenz Albe
Subject Re: BUG #18430: syntax error when using aggregate function in where clause of subquery
Date
Msg-id cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at
Whole thread Raw
In response to BUG #18430: syntax error when using aggregate function in where clause of subquery  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18430: syntax error when using aggregate function in where clause of subquery
List 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 by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18430: syntax error when using aggregate function in where clause of subquery
Next
From: Eric Atkin
Date:
Subject: Re: BUG #18430: syntax error when using aggregate function in where clause of subquery