Search Postgresql Archives

Re: Absolute value of intervals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 30, 2009 at 02:14:31PM +0200, Marko Kreen wrote:
> Slightly makes sense, but only slightly.  We deterministically know,
> that we dont have certain timestamp, thus we need to use some default
> values.  We already have situation that does that:
> 
>   extract(epoch from interval)

You're arguing the same point as me.  Your extract code and my
comparison operator use exactly the same values as defaults when
normalizing their respective intervals.  Neither of them have anything
to do with timestamps.

> Yes, some cases the value returned is not the same value that would
> be added to a specific timestamp, but so what?  How is current situation
> better that we force users to manually create potentially buggy
> equivalent functionality?

Tom was arguing that it's fundamentally inappropriate to ask for the
absolute value of an interval.  I was saying that we've already chosen
arbitrary values for the components of an interval for comparison and
you've just pointed out that we use the same values elsewhere.  Once
we've chosen them I don't see why we shouldn't extend them to all the
places that they seem to fit, such as this absolute value operator.

I think the attached trivial bit code should do the right thing, however
I don't know what else is needed to hook everything up.

-- 
  Sam  http://samason.me.uk/
*** src/backend/utils/adt/timestamp.c~	2009-06-11 15:49:04.000000000 +0100
--- src/backend/utils/adt/timestamp.c	2009-10-30 14:04:42.000000000 +0000
***************
*** 2105,2110 ****
--- 2105,2124 ----
  	PG_RETURN_INT32(interval_cmp_internal(interval1, interval2));
  }
  
+ Datum
+ interval_abs(PG_FUNCTION_ARGS)
+ {
+ 	Interval   *interval1 = PG_GETARG_INTERVAL_P(0);
+ 	Interval   *interval2 = PG_GETARG_INTERVAL_P(1);
+ 	Interval   *result;
+ 
+ 	if (interval_cmp_internal(interval1, interval2) < 0)
+ 		result = interval1;
+ 	else
+ 		result = interval2;
+ 	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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux