Re: Allow round() function to accept float and double precision

Поиск
Список
Период
Сортировка
От David Rowley
Тема Re: Allow round() function to accept float and double precision
Дата
Msg-id CAApHDvrJJineij7Vay0Pc+NAhVYvvMwd-hLoJMZc6ES3t-f=Sg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Allow round() function to accept float and double precision  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Ответы Re: Allow round() function to accept float and double precision  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Thu, 1 Dec 2022 at 21:55, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> Casting to numeric(1000, n) will work fine in all cases AFAICS (1000
> being the maximum allowed precision in a numeric typemod, and somewhat
> more memorable).

I wasn't aware of the typemod limit.

I don't really agree that it will work fine in all cases though. If
the numeric has more than 1000 digits left of the decimal point then
the method won't work at all.

# select length(('1' || repeat('0',2000))::numeric(1000,0)::text);
ERROR:  numeric field overflow
DETAIL:  A field with precision 1000, scale 0 must round to an
absolute value less than 10^1000.

No issue with round() with the same number.

# select length(round(('1' || repeat('0',2000))::numeric,0)::text);
 length
--------
   2001

David



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Error-safe user functions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Allow round() function to accept float and double precision