pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feednew max function
3+ messages / 3 participants
[nested] [flat]
* new max function
@ 2003-10-17 18:13 Rodrigo Gesswein <rodri@chilesat.net>
2003-10-17 21:32 ` Re: new max function Mike Rylander <miker@n2bb.com>
0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Gesswein @ 2003-10-17 18:13 UTC (permalink / raw)
To: pgsql-sql
Hello!
I'm looking for a function to calculate the max value from two numbers,
something like max2(a,b) with a,b int
Does anyone have the trick ?
Thank you in advance..
Rodrigo!
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: new max function
2003-10-17 18:13 new max function Rodrigo Gesswein <rodri@chilesat.net>
@ 2003-10-17 21:32 ` Mike Rylander <miker@n2bb.com>
2003-10-18 02:51 ` Re: new max function Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Mike Rylander @ 2003-10-17 21:32 UTC (permalink / raw)
To: Rodrigo Gesswein <rodri@chilesat.net>; pgsql-sql
Here's mine:
CREATE FUNCTION max2 (INTEGER,INTEGER) RETURNS INTEGER
LANGUAGE SQL AS
'SELECT CASE WHEN $1 > $2 THEN $1 ELSE $2 END';
This returns:
database=# select max2(1,2);
max2
------
2
(1 row)
database=# select max2(3,1);
max2
------
3
(1 row)
On Friday 17 October 2003 02:13 pm, Rodrigo Gesswein wrote:
> Hello!
>
> I'm looking for a function to calculate the max value from two numbers,
> something like max2(a,b) with a,b int
>
> Does anyone have the trick ?
>
> Thank you in advance..
>
> Rodrigo!
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Mike Rylander
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: new max function
2003-10-17 18:13 new max function Rodrigo Gesswein <rodri@chilesat.net>
2003-10-17 21:32 ` Re: new max function Mike Rylander <miker@n2bb.com>
@ 2003-10-18 02:51 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2003-10-18 02:51 UTC (permalink / raw)
To: miker@n2bb.com; +Cc: Rodrigo Gesswein <rodri@chilesat.net>; pgsql-sql
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, 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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-10-18 02:51 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-17 18:13 new max function Rodrigo Gesswein <rodri@chilesat.net>
2003-10-17 21:32 ` Mike Rylander <miker@n2bb.com>
2003-10-18 02:51 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox