Re: [GENERAL] Unexpected interval comparison - Mailing list pgsql-general

From Adrian Klaver
Subject Re: [GENERAL] Unexpected interval comparison
Date
Msg-id 375c9e5a-960f-942c-913f-55632a1f0a90@aklaver.com
Whole thread Raw
In response to Re: [GENERAL] Unexpected interval comparison  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Unexpected interval comparison
List pgsql-general
On 03/21/2017 07:42 AM, Tom Lane wrote:
> Frazer McLean <frazer@frazermclean.co.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 :-(

Not sure if it helps but this works:

test=# select extract(epoch from '1 year'::interval) > extract(epoch
from '32618665 years'::interval);
  ?column?
----------
  f

>
>             regards, tom lane
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [GENERAL] Unexpected interval comparison
Next
From: "Klaus P. Pieper"
Date:
Subject: Re: [GENERAL] Why is this functional index not used?