public inbox for [email protected]  
help / color / mirror / Atom feed
From: PG Doc comments form <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Unclear documentation and requirement of clarification
Date: Thu, 16 Apr 2026 13:32:48 +0000
Message-ID: <[email protected]> (raw)

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/18/tutorial-agg.html
Description:

Notice this particular section in the documentation of 2.7 Aggregrate
Functions (https://www.postgresql.org/docs/current/tutorial-agg.html) :
"If we wanted to know what city (or cities) that reading occurred in, we
might try:

SELECT city FROM weather WHERE temp_lo = max(temp_lo);     -- WRONG
but this will not work since the aggregate max cannot be used in the WHERE
clause. (This restriction exists because the WHERE clause determines which
rows will be included in the aggregate calculation; so obviously it has to
be evaluated before aggregate functions are computed.) However, as is often
the case the query can be restated to accomplish the desired result, here by
using a subquery:

SELECT city FROM weather
    WHERE temp_lo = (SELECT max(temp_lo) FROM weather);"

This would be better off if it's mentioned that in this particular case, we
actually need the aggregate function to be computed before the WHERE clause
and that's why we are using a subquery.






view thread (2+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Unclear documentation and requirement of clarification
  In-Reply-To: <[email protected]>

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

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