Re: BUG #17150: Unexpected outputs from the query

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "luy70(at)psu(dot)edu" <luy70(at)psu(dot)edu>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17150: Unexpected outputs from the query
Date: 2021-08-17 18:27:10
Message-ID: CAKFQuwaxSxw+T3dmyOoNLW=zrL5yPz3_ecaVMdVyihYCTMa9rw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tuesday, August 17, 2021, PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> This
> unexpected return can be fixed by removing "ORDER BY ( SELECT COUNT ( v1
> )
> )", then the query returns sum="0" as expected.
>

Well, PostgreSQL cannot remove the order by otherwise it would be a
different query. So your suggestion is spot on, and the user should
probably do that, but it doesn’t seem like a bug.

As "SELECT 1" returns a single row (even though there isn't even a from
clause) the fact that "select count(*)" returns a row with a count of 1
isn't surprising - it always returns at least one row. So the order by
expression adds a row to the output. This may be surprising but is also a
natural consequence of allowing pretty much any desired expression to
appear in the order by clause.

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-08-17 18:56:43 Re: BUG #17150: Unexpected outputs from the query
Previous Message Euler Taveira 2021-08-17 17:00:15 Re: BUG #17148: About --no-strict-names option and --quiet option of pg_amcheck command