On Fri, Oct 30, 2009 at 11:39:26AM -0300, Alvaro Herrera wrote: > Sam Mason wrote: > > + Datum > > + interval_abs(PG_FUNCTION_ARGS) > > + { > > + Interval *interval1 = PG_GETARG_INTERVAL_P(0); > > + Interval *interval2 = PG_GETARG_INTERVAL_P(1); > > Surely it must receive a single argument? Indeed it must, trying to write other code at the same time is a good recipe for getting myself in a mess! -- Sam http://samason.me.uk/
*** src/backend/utils/adt/timestamp.c~ 2009-10-30 14:45:40.000000000 +0000 --- src/backend/utils/adt/timestamp.c 2009-10-30 14:47:06.000000000 +0000 *************** *** 2105,2110 **** --- 2105,2128 ---- PG_RETURN_INT32(interval_cmp_internal(interval1, interval2)); } + Datum + interval_abs(PG_FUNCTION_ARGS) + { + Interval *interval = PG_GETARG_INTERVAL_P(0); + Interval *result, *intervalneg; + + intervalneg = (Interval *) palloc(sizeof(Interval)); + intervalneg->time = -interval->time; + intervalneg->day = -interval->day; + intervalneg->month = -interval->month; + + if (interval_cmp_internal(interval, intervalneg) < 0) + result = intervalneg; + else + result = interval; + PG_RETURN_INTERVAL_P(result); + } + /* * Hashing for intervals *
-- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general