Question about integer out of range in function - Mailing list pgsql-general

From David G. Johnston
Subject Question about integer out of range in function
Date
Msg-id CAKFQuwZ+WPMGPF5c4evn+q83P8mLe4UhZnJepSG5AS9=b8ciyg@mail.gmail.com
Whole thread Raw
In response to Re: Question about integer out of range in function  (Condor <condor@stz-bg.com>)
Responses Re: Question about integer out of range in function
List pgsql-general
On Sunday, May 16, 2021, Condor <condor@stz-bg.com> wrote:

     new_time = fromtime * 1000; -- here is line 19
     

An integer times an integer results in an integer.  Period.  Neither fromtime nor new_time have been assigned to yet, the in-memory result of the computation is only allocated integer bits and if you overflow that you get an error.  If there is no error the result of that computation is stored in new_time.  Since new_time is a bigint during assignment the in-memory integer is implicitly converted to bigint to match the assignment type.

Either fromtime or the 1000 need to be declared as bigint if you want the computation type to be bigint as well, and thus avoid the overflow.  The implicit cast to store into new_time goes away.  And whichever, if any, of the two values you do not change to bigint gets implicitly cast to bigint in order for the multiplication operator to match “*(bigint,bigint)”.

David J.

pgsql-general by date:

Previous
From: Condor
Date:
Subject: Re: Question about integer out of range in function
Next
From: Loles
Date:
Subject: