Re: WITHIN GROUP patch

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: WITHIN GROUP patch
Date: 2013-12-06 22:12:34
Message-ID: 8738m5fxu5.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Josh" == Josh Berkus <josh(at)agliodbs(dot)com> writes:

>> Since I don't particularly trust my own judgement on aesthetics, I
>> used the feedback I got from others when deciding what to
>> do. Frankly I think this one needs wider input than just you and
>> me arguing over it.

Josh> Can someone paste examples of the two syntax alternatives we're
Josh> talking about here? I've lost track.

OK. The starting point is that this is the calling syntax for ordered
set funcs, set by the spec:

SELECT func(foo) WITHIN GROUP (ORDER BY bar) FROM ...

where "foo" and "bar" might be fixed types, or polymorphic or variadic.

So we need to define (with no help from the spec) at least these:

- what syntax is used in CREATE AGGREGATE to specify the number and
types of parameters for a newly defined "func"

- what syntax is used to refer to the function in a
GRANT ... ON FUNCTION ... statement, or ALTER ... OWNER TO ...

- what should ::regprocedure casts accept as input and produce as
output

- what output is shown in \df and \da when listing the function's
argument types

The patch as submitted answers those questions as follows:

CREATE AGGREGATE func(integer) WITHIN GROUP (text) ...

GRANT ... ON FUNCTION func(integer,text) ...
(there is no GRANT ... ON AGGREGATE ... (yet))

ALTER AGGREGATE func(integer) WITHIN GROUP (text) OWNER TO ...
ALTER AGGREGATE func(integer,text) OWNER TO ...
ALTER FUNCTION func(integer,text) OWNER TO ...
(all three of those are equivalent)

regprocedure outputs 'func(integer,text)' and accepts only that as
input

postgres=# \df func
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+------+------------------+-------------------------------+------
public | func | text | (integer) WITHIN GROUP (text) | agg
(1 row)

If there's also a func() that isn't an ordered set function, you get
output like this (which provoked tom's "schitzophrenic" comment):

postgres=# \df ran[a-z]{1,5}
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+----------+------------------+-----------------------------------+--------
pg_catalog | random | double precision | | normal
pg_catalog | rangesel | double precision | internal, oid, internal, integer | normal
pg_catalog | rank | bigint | | window
pg_catalog | rank | bigint | (VARIADIC "any") WITHIN GROUP (*) | agg
(4 rows)

--
Andrew (irc:RhodiumToad)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-12-06 22:41:41 Re: WITHIN GROUP patch
Previous Message Peter Eisentraut 2013-12-06 21:59:52 Re: RFC: programmable file format for postgresql.conf