Re: WITHIN GROUP patch - Mailing list pgsql-hackers

From Tom Lane
Subject Re: WITHIN GROUP patch
Date
Msg-id 19933.1386365257@sss.pgh.pa.us
Whole thread Raw
In response to Re: WITHIN GROUP patch  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Responses Re: WITHIN GROUP patch
List pgsql-hackers
Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:
>  Tom> Actually, now that I think of it, why not use this syntax for
>  Tom> declaration and display purposes:
>  Tom>     type1, type2 ORDER BY type3, type4

> But unfortunately it looks exactly like the calling sequence for a
> normal aggregate with an order by clause - I really think that is
> potentially too much confusion.

I thought about that too, but really that ship sailed long ago, and it
went to sea under the SQL committee's captaincy, so it's not our fault.
There are already at least four different standards-blessed ways you can
use ORDER BY in a query, some of them quite nearby (eg window functions);
so the potential for confusion is there no matter what we do.  In this
case, if we describe ordered-set aggregates using WITHIN GROUP rather than
ORDER BY, we might avoid confusion with the normal-aggregate case, but
instead we will have confusion about what the arguments even do.  Is
semantic confusion better than syntactic confusion?

Another thing to think about here is to wonder why the committee chose
anything as verbose as "agg(...) WITHIN GROUP (ORDER BY ...)" in the
first place.  The words ORDER BY certainly seem pretty unnecessary.
I'm suspicious that they might've been leaving the door open to put other
things into the second set of parens later --- GROUP BY, maybe?  So down
the road, we might regret it if we key off WITHIN GROUP and not ORDER BY.

Having said that, I'm not so dead set on it that I won't take WITHIN GROUP
if that's what more people want.  But we gotta lose the extra parens; they
are just too strange for function declaration/documentation purposes.
        regards, tom lane



pgsql-hackers by date:

Previous
From: David Johnston
Date:
Subject: Re: WITHIN GROUP patch
Next
From: Andrew Gierth
Date:
Subject: Re: WITHIN GROUP patch