postgresql - Syntax error in create aggregate -
trying create aggregate function:
create aggregate min (my_type) ( sfunc = least, stype = my_type ); error: syntax error @ or near "least" line 2: sfunc = least, ^ what missing?
although manual calls least function:
the greatest , least functions select largest or smallest value list of number of expressions.
i can not find it:
\dfs least list of functions schema | name | result data type | argument data types | type --------+------+------------------+---------------------+------ (0 rows)
least , greatest not real functions; internally parsed minmaxexpr (see src/include/nodes/primnodes.h).
you achieve want generic function this:
create function my_least(anyelement, anyelement) returns anyelement language sql immutable called on null input 'select least($1, $2)'; (thanks erwin brandstetter called on null input , idea use least.)
then can create aggregate as
create aggregate min(my_type) (sfunc = my_least, stype = my_type); this work if there comparison functions my_type, otherwise have come different my_least function.
Comments
Post a Comment