Re: Aggregate error message

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Aggregate error message
Date: 2019-05-24 07:20:35
Message-ID: CAKJS1f8yYUYUfmjEZdDftsTNBqHaC=kEaiRGfQb9S0JoLxiN_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 24 May 2019 at 18:17, Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com> wrote:
>
> With a sample query such as
>
> SELECT x, avg(x)
> FROM (VALUES (1), (2), (3)) AS v (x);
>
> We give the error message "column "v.x" must appear in the GROUP BY
> clause or be used in an aggregate function".
>
> This is correct but incomplete. Attached is a trivial patch to also
> suggest that the user might have been trying to use a window function.

I think you might have misthought this one. If there's an aggregate
function in the SELECT or HAVING clause, then anything else in the
SELECT clause is going to have to be either in the GROUP BY clause, be
functionally dependent on the GROUP BY clause, or be in an aggregate
function. Putting it into a window function won't help the situation.

postgres=# select sum(x) over(),avg(x) FROM (VALUES (1), (2), (3)) AS v (x);
psql: ERROR: column "v.x" must appear in the GROUP BY clause or be
used in an aggregate function
LINE 1: select sum(x) over(),avg(x) FROM (VALUES (1), (2), (3)) AS v...
^

If there's any change to make to the error message then it would be to
add the functional dependency part, but since we're pretty bad at
detecting that, I don't think we should.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message didier 2019-05-24 07:40:36 Re: [HACKERS] Small fix: avoid passing null pointers to memcpy()
Previous Message Vik Fearing 2019-05-24 06:17:12 Aggregate error message