Re: Unexpected interval comparison

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Frazer McLean <frazer(at)frazermclean(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected interval comparison
Date: 2017-03-21 14:42:16
Message-ID: 30765.1490107336@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Frazer McLean <frazer(at)frazermclean(dot)co(dot)uk> writes:
> I came across an unexpected comparison (tested on PostgreSQL 9.4 and
> 9.6) for intervals with a large difference in magnitude.

> '1 year'::interval > '32618665 years'::interval;

> Is this a bug?

It looks like the problem is overflow of the result of interval_cmp_value,
because it's trying to compute

=# select '32618665'::int8 * 30 * 86400 * 1000000;
ERROR: bigint out of range

It's not immediately obvious how to avoid that while preserving the same
comparison semantics :-(

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2017-03-21 14:52:25 Re: Unexpected interval comparison
Previous Message Frazer McLean 2017-03-21 13:57:09 Unexpected interval comparison