Re: [SQL] Interval subtracting

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Mark Dilger <pgsql(at)markdilger(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [SQL] Interval subtracting
Date: 2006-03-01 20:13:15
Message-ID: 200603012013.k21KDFM21139@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

Mark Dilger wrote:
> select justify_hours('-73 hours'::interval);
> justify_hours
> -------------------
> -4 days +23:00:00
>
> select justify_days('-62 days'::interval);
> justify_days
> ------------------
> -3 mons +28 days
>
>
> I find the last two results somewhat peculiar, as the new functionality
> pushes the negative values upwards (from hours to days, days to months).
> Changing '-73 hours' to '-3 days -1 hour' might be more intuitive?
> The '-4 days +23 hours' is however consistent with the behavior in the
> other cases.

I don't think we can accept a change that takes a negative and turns it
into a positive and negative. I think the answer to the last one should
be '-2 mons -2 days', which is what it does now:

test=> select justify_days('-62 days'::interval);
justify_days
-----------------
-2 mons -2 days
(1 row)

The open question is whether we should convert a positive and negative
to a positive, or a negative, based on the sign of the highest value,
e.g. convert '1 mons -10 days' to '20 days', and '-1 mons 10 days' to
'-20 days'?

--
Bruce Momjian http://candle.pha.pa.us
SRA OSS, Inc. http://www.sraoss.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bernd Helmle 2006-03-01 20:18:29 Re: Automatic free space map filling
Previous Message Michael Fuhr 2006-03-01 19:59:59 Re: bug in 7.3.2

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2006-03-01 20:18:43 Re: [SQL] Interval subtracting
Previous Message Mark Dilger 2006-03-01 18:39:58 Re: [SQL] Interval subtracting

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2006-03-01 20:18:43 Re: [SQL] Interval subtracting
Previous Message Scott Marlowe 2006-03-01 20:09:39 Re: Replication - state of the art?