create function w/indeterminate number of args? - Mailing list pgsql-sql

From Andrew Perrin
Subject create function w/indeterminate number of args?
Date
Msg-id Pine.LNX.4.21.0102260001380.8089-100000@nujoma.perrins
Whole thread Raw
List pgsql-sql
Greetings.

I find myself in need of a minimum() function. This is different from the
min() function, which operates across records; what I need is to be able
to say:

UPDATE foo SET newcol = minimum(field1, field2, field3, field4);

From what I can tell there is no such beast built in, but I would be happy
to be proved wrong.

Anyway... I can write such a function easily enough in perl, probably
something like:
 my $min=$_[0]; $min > $_ and $min = $_ foreach @_; return $min;

but I can't determine how to allow varying numbers of arguments to be
passed to a function. That is, sometimes I need minimum(arg1, arg2) but
sometimes it's minimum(arg1, arg2, arg3, arg4, arg5), etc.  

Thanks-
Andy Perrin

----------------------------------------------------------------------
Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology  
Chapel Hill, North Carolina, USA - http://demog.berkeley.edu/~aperrin       aperrin@socrates.berkeley.edu -
aperrin@igc.apc.org



pgsql-sql by date:

Previous
From: Ken Kline
Date:
Subject: Re: conversion
Next
From: Christopher Sawtell
Date:
Subject: Re: conversion