In trying to learn about aggregates, I came across this seemingly odd
behavior:
(postgres@[local]:5435 08:27:42) [postgres]> CREATE AGGREGATE example_max (TEXT) (SFUNC = greatest, STYPE = TEXT);
ERROR: syntax error at or near "greatest"
LINE 1: CREATE AGGREGATE example_max (TEXT) (SFUNC = greatest, STYPE...
^
Of course, this is a silly example (one could just use max), but I'm
interested in knowing why greatest cannot be used here. Someone on IRC
mentioned that it was because "greatest was not actually a function" but
the documentation for greatest says nothing along those lines:
http://www.postgresql.org/docs/9.2/static/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
The documentation also indicates that greatest is non-reserved (cannot
be function or type):
http://www.postgresql.org/docs/9.2/static/sql-keywords-appendix.html
But I'm not sure I understand how to interpret the "cannot be function
or type" or portion of that.
Quoting "greatest" causes this error instead:
(postgres@[local]:5435 08:30:08) [postgres]> CREATE AGGREGATE example_max (TEXT) (SFUNC = "greatest", STYPE = TEXT);
ERROR: function greatest(text, text) does not exist
Which I would assume is because greatest is variadic and not simply a
function of two arguments.
I'm sure I'm just being dense and missing something obvious here...
-Ryan P. Kelly