pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: dan.farlow@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16900: SELECT MAX subquery not allowed in WHERE clause when using WITH RECURSIVE
Date: Fri, 26 Feb 2021 11:40:13 -0500
Message-ID: <287738.1614357613@sss.pgh.pa.us> (raw)
In-Reply-To: <16900-5b4d30739ea178c7@postgresql.org>
References: <16900-5b4d30739ea178c7@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> CREATE TABLE IF NOT EXISTS
>   Tasks (task_id int, subtasks_count int);
> ...

>   UNION ALL
>   SELECT
>     task_id, max_subtask_count, subtask_id + 1
>   FROM
>     possible_tasks_subtasks
>   -- using SELECT MAX in the WHERE clause below is what causes the error
>   WHERE
>     subtask_id < (SELECT MAX(max_subtask_count) FROM Tasks))

max_subtask_count is not a field of Tasks; perhaps you meant to
write MAX(subtasks_count)?

As the query is written, the aggregate is over a field of
possible_tasks_subtasks, making it illegal in WHERE, just
as the error says.  (From the point of view of the "SELECT FROM Tasks"
subquery, it's a constant outer reference, not an aggregate of
that subquery.  This is per SQL spec.)

			regards, tom lane





view thread (4+ messages)  latest in thread

Message-ID: <287738.1614357613@sss.pgh.pa.us>
Permalink:  ../287738.1614357613@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/287738.1614357613@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dan.farlow@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16900: SELECT MAX subquery not allowed in WHERE clause when using WITH RECURSIVE
  In-Reply-To: <287738.1614357613@sss.pgh.pa.us>

* 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