Re: new max function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: miker(at)n2bb(dot)com
Cc: Rodrigo Gesswein <rodri(at)chilesat(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: new max function
Date: 2003-10-18 02:51:52
Message-ID: 27573.1066445512@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mike Rylander <miker(at)n2bb(dot)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, money
date | pg_catalog | date_larger | date, date
real | pg_catalog | float4larger | real, real
double precision | pg_catalog | float8larger | double precision, double precision
smallint | pg_catalog | int2larger | smallint, smallint
integer | pg_catalog | int4larger | integer, integer
bigint | pg_catalog | int8larger | bigint, bigint
interval | pg_catalog | interval_larger | interval, interval
numeric | pg_catalog | numeric_larger | numeric, numeric
oid | pg_catalog | oidlarger | oid, oid
text | pg_catalog | text_larger | text, text
time without time zone | pg_catalog | time_larger | time without time zone, time without time zone
timestamp without time zone | pg_catalog | timestamp_larger | timestamp without time zone, timestamp without time zone
timestamp with time zone | pg_catalog | timestamptz_larger | timestamp with time zone, timestamp with time zone
time with time zone | pg_catalog | timetz_larger | time with time zone, time with time zone
(15 rows)

All of these have matching xxxsmaller() as well.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Roberto Mello 2003-10-18 18:52:08 Re: Postgres with OpenSSL
Previous Message Mike Rylander 2003-10-17 21:32:50 Re: new max function