greatest cannot be used as sfunc for CREATE AGGREGATE - Mailing list pgsql-general

From Ryan Kelly
Subject greatest cannot be used as sfunc for CREATE AGGREGATE
Date
Msg-id 20130625123947.GA24810@llserver.lakeliving.com
Whole thread Raw
Responses Re: greatest cannot be used as sfunc for CREATE AGGREGATE
List pgsql-general
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



pgsql-general by date:

Previous
From: Daniel Cristian Cruz
Date:
Subject: Debian Weezy PGDG CD/DVD iso image
Next
From: dinesh kumar
Date:
Subject: PostgreSQL 9.3 pg_dump issue