Re: Syntax bug? Group by? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Syntax bug? Group by?
Date
Msg-id 11881.1161120113@sss.pgh.pa.us
Whole thread Raw
In response to Re: Syntax bug? Group by?  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: Syntax bug? Group by?  ("Przemek " <krycek6@wp.pl>)
List pgsql-hackers
Andrew Dunstan <andrew@dunslane.net> writes:
> Mark Woodward wrote:
>> My question, is it a syntactic technicality that PostgreSQL asks for a
>> "group by," or a bug in the parser?

> AFAIK what you want is not per sql spec.

It would in fact be a violation of spec.  Consider the case where there
are no rows matching 15.  In this case

select min(tindex), avg(tindex) from y where ycis_id = 15;

will yield one row containing NULLs, whereas

select min(tindex), avg(tindex) from y where ycis_id = 15 group by ycis_id;

will yield no rows (because there are no groups).  Therefore, if
Postgres were to implicitly insert a GROUP BY to make it legal to
reference ycis_id directly, we'd be changing the query behavior
and breaking spec.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Syntax bug? Group by?
Next
From: Shane Ambler
Date:
Subject: Re: Syntax bug? Group by?