pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Mark Dilger <pgsql@markdilger.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [SQL] Interval subtracting
Date: Wed, 1 Mar 2006 16:45:27 -0500 (EST)
Message-ID: <200603012145.k21LjRX11928@candle.pha.pa.us> (raw)
In-Reply-To: <44061060.8080407@markdilger.com>

Mark Dilger wrote:
> Your proposal is that justify_hours borrows 24 hours from the days column in 
> order to bring the -12 hours up to a positive 12 hours.  Should it only do that 
> if the days column is a positive number?  What if it is negative?
> 
> I think we all agree on the following but nobody is explicitly saying so:
> 
>    select justify_days(justify_hours('2 days -12:00:00'::interval))
>          justify_days
>    -------------------------
>     1 day 12:00:00

Right.

>    select justify_days(justify_hours('-2 days -12:00:00'::interval))
>          justify_days
>    -------------------------
>     -2 days -12:00:00

Right, unchanged.

> Am I correct that the second case should still have negative hours?  If so, then 
> justify_hours(...) needs to examine the sign of the days and months portion of 
> the interval while performing its work.

Yes, it would need to look at both, and this opens a new problem. 
Imagine this:

	'1 mons -2 days -12:00:00'

Which sign do we head to for this?  For justify_hours, if we don't look
at the months it remains unchange, but calling justify_days we get:

	'28 days -12:00:00'

which is wrong (negative and positive).  Now if we knew justify_days was
going to be called we would have had justify_hours return '-3 days
12:00:00' so the final result after calling justify_days would be '27
days 12:00:00'.

My head hurts.

-- 
  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. +



view thread (62+ messages)  latest in thread

Message-ID: <200603012145.k21LjRX11928@candle.pha.pa.us>
Permalink:  ../200603012145.k21LjRX11928@candle.pha.pa.us/
Also on:    postgresql.org/message-id/200603012145.k21LjRX11928@candle.pha.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pgman@candle.pha.pa.us, pgsql@markdilger.com, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org
  Subject: Re: [SQL] Interval subtracting
  In-Reply-To: <200603012145.k21LjRX11928@candle.pha.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox