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

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Sayyid Ali Sajjad Rizavi <sasrizavi(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Allow round() function to accept float and double precision
Date: 2022-12-01 19:57:17
Message-ID: CAApHDvrJJineij7Vay0Pc+NAhVYvvMwd-hLoJMZc6ES3t-f=Sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 1 Dec 2022 at 21:55, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-12-01 20:02:09 Re: Allow round() function to accept float and double precision
Previous Message Tom Lane 2022-12-01 19:41:11 Re: Error-safe user functions