Mike Rylander <miker@n2bb.com> writes:
> Here's mine:
> CREATE FUNCTION max2 (INTEGER,INTEGER) RETURNS INTEGER
> LANGUAGE SQL AS
> 'SELECT CASE WHEN $1 > $2 THEN $1 ELSE $2 END';
BTW, most of the standard datatypes have these already, because they are
the transition functions for the MAX() and MIN() aggregates. The one
above is int4larger().
regression=# \df *larger List of functions Result data type
| Schema | Name | Argument data types
-----------------------------+------------+--------------------+----------------------------------------------------------money
| pg_catalog | cashlarger | money, moneydate | pg_catalog |
date_larger | date, datereal | pg_catalog | float4larger | real, realdouble
precision | pg_catalog | float8larger | double precision, double precisionsmallint |
pg_catalog| int2larger | smallint, smallintinteger | pg_catalog | int4larger |
integer,integerbigint | pg_catalog | int8larger | bigint, bigintinterval
| pg_catalog | interval_larger | interval, intervalnumeric | pg_catalog | numeric_larger |
numeric,numericoid | pg_catalog | oidlarger | oid, oidtext |
pg_catalog| text_larger | text, texttime without time zone | pg_catalog | time_larger | time without
timezone, time without time zonetimestamp without time zone | pg_catalog | timestamp_larger | timestamp without time
zone,timestamp without time zonetimestamp with time zone | pg_catalog | timestamptz_larger | timestamp with time
zone,timestamp with time zonetime with time zone | pg_catalog | timetz_larger | time with time zone, time
withtime zone
(15 rows)
All of these have matching xxxsmaller() as well.
regards, tom lane