Re: [SQL] Interval subtracting

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Milen A(dot) Radev" <milen(at)radev(dot)net>, pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [SQL] Interval subtracting
Date: 2006-02-18 19:03:39
Message-ID: 20060218110129.W9818@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

On Sat, 18 Feb 2006, 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.

What about cases like interval '1 month -99 days', should that turn into
interval '-3 mons +21 days' or '-2 mons -9 days'?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua D. Drake 2006-02-18 19:04:16 Re: Pgfoundry and gborg: shut one down
Previous Message Martin Pitt 2006-02-18 19:00:38 Re: Adding an ignore list to pg_restore

Browse pgsql-patches by date

  From Date Subject
Next Message Neil Conway 2006-02-18 20:28:09 Re: add additional options to CREATE TABLE ... AS
Previous Message Tom Lane 2006-02-18 18:30:14 Re: [SQL] Interval subtracting

Browse pgsql-sql by date

  From Date Subject
Next Message Janning Vygen 2006-02-19 10:44:34 Re: Need help: Find dirty rows, Update, Delete SQL
Previous Message Tom Lane 2006-02-18 18:30:14 Re: [SQL] Interval subtracting