Search Postgresql Archives

Question about integer out of range in function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sunday, May 16, 2021, Condor <condor@xxxxxxxxxx> 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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux