greatest cannot be used as sfunc for CREATE AGGREGATE

From: Ryan Kelly <rpkelly22(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: greatest cannot be used as sfunc for CREATE AGGREGATE
Date: 2013-06-25 12:39:47
Message-ID: 20130625123947.GA24810@llserver.lakeliving.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In trying to learn about aggregates, I came across this seemingly odd
behavior:

(postgres(at)[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(at)[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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message dinesh kumar 2013-06-25 13:08:39 PostgreSQL 9.3 pg_dump issue
Previous Message Daniel Cristian Cruz 2013-06-25 11:24:47 Debian Weezy PGDG CD/DVD iso image