Re: [HACKERS] Interval aggregate regression failure

Bruce Momjian <bruce@momjian.us>

From: Bruce Momjian <bruce@momjian.us>
To: Michael Glaesemann <grzm@seespotcode.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Michael Paesold <mpaesold@gmx.at>, PostgreSQL-patches <pgsql-patches@postgresql.org>
Date: 2006-08-30T17:08:45Z
Lists: pgsql-hackers

Attachments

Michael Glaesemann wrote:
> > Yea, just an optimization, but I was worried that the computations  
> > might
> > throw problems for certain numbers, so I figured I would only  
> > trigger it
> > when necessary.
> 
> Thanks for the explanation. Helps me know I might actually be  
> learning this.
> 
> > Patch attached.  It also fixes a regression test output too.
> 
> Thanks for the patch. I'll look at it more closely tonight.

OK, here is a much nicer patch.  The fix is to do no rounding, but to
find the number of days before applying the factor adjustment.  It
passes all your tests here:

	test=> select '41 mon 10:00:00'::interval / 10 as "pos";
	          pos
	------------------------
	 4 mons 3 days 01:00:00
	(1 row)
	
	test=> select interval '41 mon 12 days 360:00' * 0.3 as product_a
	     , interval '41 mon -12 days -360:00' * 0.3 as product_b
	     , interval '-41 mon 12 days 360:00' * 0.3 as product_c
	     , interval '-41 mon -12 days -360:00' * 0.3 as product_d;
	        product_a         |        product_b         |         
	product_c          |          product_d
	--------------------------+--------------------------+-----------------------------+------------------------------
	
	 1 year 12 days 122:24:00 | 1 year 6 days -122:24:00 | -1 years -6 days
	+122:24:00 | -1 years -12 days -122:24:00
	(1 row)
	
	test=> select interval '41 mon 12 days 360:00' / 10 as quotient_a
	     , interval '41 mon -12 days -360:00' / 10 as quotient_b
	     , interval '-41 mon 12 days 360:00' / 10 as quotient_c
	     , interval '-41 mon -12 days -360:00' / 10 as quotient_d;
	       quotient_a       |       quotient_b        |        quotient_c   
	     |        quotient_d
	------------------------+-------------------------+---------------------------+---------------------------
	
	 4 mons 4 days 40:48:00 | 4 mons 2 days -40:48:00 | -4 mons -2 days
	+40:48:00 | -4 mons -4 days -40:48:00
	(1 row)

What do you see on your platform?

-- 
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

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