Re: seeming overflow during avg() of intervals without errors/warnings

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Vick Khera <vivek(at)khera(dot)org>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: seeming overflow during avg() of intervals without errors/warnings
Date: 2013-05-15 14:50:41
Message-ID: 26350.1368629441@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Vick Khera <vivek(at)khera(dot)org> writes:
> So basically, it seems like however avg() on intervals is being computed it
> is overflowing somewhere without warning.

Hmmm ... yeah, it looks like interval_pl is missing any overflow check:

regression=# select '2147483648 days'::interval;
ERROR: interval field value out of range: "2147483648 days"
LINE 1: select '2147483648 days'::interval;
^
regression=# select '2147483647 days'::interval;
interval
-----------------
2147483647 days
(1 row)

regression=# select '2147483647 days'::interval + '1 day'::interval;
?column?
------------------
-2147483648 days
(1 row)

Somebody ought to fix that.

A larger question is whether it'd be worth the trouble for interval
avg() to use some wider internal representation so it could avoid
the overflow. Given the lack of prior complaints I'm inclined to
suspect it's not.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jorge Arévalo 2013-05-15 15:08:33 Best way to reduce server rounds getting big BLOBs
Previous Message Merlin Moncure 2013-05-15 14:48:18 Re: Re: volatile void returning function not executed as often as expected in sql function