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: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [SQL] Interval subtracting
Date: 2006-03-01 17:59:29
Message-ID: 200603011759.k21HxT320151@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

Mark Dilger wrote:
> Tom Lane wrote:
> > "Milen A. Radev" <milen(at)radev(dot)net> writes:
> >
> >>Milorad Poluga ????????????:
> >>
> >>>>SELECT '10 years 1 mons 1 days'::interval - '9 years 10 mons 15 days'::interval
> >>>>?column?
> >>>>---------------
> >>>>3 mons -14 days
> >>>>
> >>>>Why not '2 mons 16 days' ?
> >
> >
> >>Please read the last paragraph in section 8.5.1.4 of the manual
> >>(http://www.postgresql.org/docs/8.1/static/datatype-datetime.html#AEN4775)
> >>. It mentions the functions named "justify_days" and "justify_hours"
> >>that could do what you need.
> >
> >
> > justify_days doesn't currently do anything with this result --- it
> > thinks its charter is only to reduce day components that are >= 30 days.
> > However, I think a good case could be made that it should normalize
> > negative days too; that is, the invariant on its result should be
> > 0 <= days < 30, not merely days < 30. Similarly for justify_hours.
> > Comments anyone? Patch anyone?
>
> Sure, if nobody objects to this change I can write the patch.

Good question. Should we restrict days to 0 - 30 or -30 - 30? The
current system does the later:

test=> select justify_days('-45 days');
justify_days
------------------
-1 mons -15 days
(1 row)

test=> select justify_days('1 month -45 days');
justify_days
--------------
-15 days
(1 row)

test=> select justify_days('1 month -15 days');
justify_days
----------------
1 mon -15 days
(1 row)

Should we be adjusting the last one? I am unsure. Comments?

--
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 Mark Dilger 2006-03-01 18:06:37 Re: [SQL] Interval subtracting
Previous Message Alvaro Herrera 2006-03-01 17:51:59 Re: Automatic free space map filling

Browse pgsql-patches by date

  From Date Subject
Next Message Mark Dilger 2006-03-01 18:06:37 Re: [SQL] Interval subtracting
Previous Message Mark Dilger 2006-03-01 17:05:09 Re: [SQL] Interval subtracting

Browse pgsql-sql by date

  From Date Subject
Next Message Mark Dilger 2006-03-01 18:06:37 Re: [SQL] Interval subtracting
Previous Message Bruno Wolff III 2006-03-01 17:59:04 Re: grant select,... over schema