pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: eatkin@certusllc.us
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18430: syntax error when using aggregate function in where clause of subquery
Date: Fri, 12 Apr 2024 19:44:59 +0200
Message-ID: <cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at> (raw)
In-Reply-To: <18430-f06d523d31f29af7@postgresql.org>
References: <18430-f06d523d31f29af7@postgresql.org>

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





view thread (6+ messages)  latest in thread

Message-ID: <cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at>
Permalink:  ../cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at/
Also on:    postgresql.org/message-id/cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: laurenz.albe@cybertec.at, eatkin@certusllc.us
  Subject: Re: BUG #18430: syntax error when using aggregate function in where clause of subquery
  In-Reply-To: <cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at>
  References: <18430-f06d523d31f29af7@postgresql.org> <cd61a2c86437acce0624280e3998bcacd5f48cc9.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox