Question about integer out of range in function

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Question about integer out of range in function
Дата
Msg-id CAKFQuwZ+WPMGPF5c4evn+q83P8mLe4UhZnJepSG5AS9=b8ciyg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Question about integer out of range in function  (Condor <condor@stz-bg.com>)
Ответы Re: Question about integer out of range in function  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
Список 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 по дате отправления:

Предыдущее
От: Condor
Дата:
Сообщение: Re: Question about integer out of range in function
Следующее
От: Loles
Дата:
Сообщение: