Re: [HACKERS] timestamp subtraction (was Re: formatting intervals with to_char)

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Jim Nasby <jimn(at)enterprisedb(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, gdavis(at)refractions(dot)net, pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] timestamp subtraction (was Re: formatting intervals with to_char)
Date: 2007-02-21 01:07:11
Message-ID: 200702210107.l1L17Bm21179@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql


One problem with removing justify_hours() is that this is going to
return '24:00:00', rather than '1 day:

test=> select '2004-01-02 00:00:00'::timestamptz - '2004-01-01
00:00:00'::timestamptz;
?column?
----------
24:00:00
(1 row)

---------------------------------------------------------------------------

Jim Nasby wrote:
> On Oct 5, 2006, at 11:50 AM, Tom Lane wrote:
> > regression=# select ('2006-09-15 23:59:00'::timestamp - '2006-09-01
> > 09:30:41'::timestamp);
> > ?column?
> > ------------------
> > 14 days 14:28:19
> > (1 row)
> >
> > should be reporting '350:28:19' instead.
> >
> > This is a hack that was done to minimize the changes in the regression
> > test expected outputs when we changed type interval from months/
> > seconds
> > to months/days/seconds. But I wonder whether it wasn't a dumb idea.
> > It is certainly inconsistent, as noted in the code comments.
> >
> > I'm tempted to propose that we remove the justify_hours call, and tell
> > anyone who really wants the old results to apply justify_hours() to
> > the
> > subtraction result for themselves. Not sure what the fallout would
> > be,
> > though.
>
> I suspect there's applications out there that are relying on that
> being nicely formated for display purposes.
>
> I agree it should be removed, but we might need a form of backwards
> compatibility for a version or two...
> --
> Jim Nasby jimn(at)enterprisedb(dot)com
> EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.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 Tom Lane 2007-02-21 01:08:18 Re: WIP patch - INSERT-able log statements
Previous Message Robert Treat 2007-02-21 00:54:42 Re: Column storage positions

Browse pgsql-sql by date

  From Date Subject
Next Message devil live 2007-02-21 11:31:02 Problem with Temp Table and Result Set from PL Function...
Previous Message Phillip Smith 2007-02-20 22:12:24 Re: DISTINCT ON not working...?