## Re: precision and scale functions for numeric

From: Robert Haas Peter Eisentraut pgsql-hackers Re: precision and scale functions for numeric 2012-04-30 18:19:44 CA+TgmoZzMbYUBEDftvp1OooRWppTDOv_swwusLaJfhj+pXpcRA@mail.gmail.com (view raw, whole thread or download thread mbox) 2012-04-29 17:51:37 from Peter Eisentraut  2012-04-30 18:19:44 from Robert Haas   2012-04-30 19:33:48 from "David Johnston"    2012-04-30 19:39:43 from Robert Haas    2012-04-30 19:40:41 from "Kevin Grittner" pgsql-hackers
```On Sun, Apr 29, 2012 at 1:51 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> I didn't find a good way to find out how many digits a numeric value has
> or things like whether a numeric value is an integer.  (I had to go
> through bc(1) for the latter.)  Functions like precision() and scale()
> would have been quite handy.  Are there other ways to do this, or would
> this make a good addition?

I think you could test for integer-ness by testing whether val % 0 = 0.

You could in general test of digits after the decimal point by casting
the value to text and using POSITION() to find the decimal point.  If
POSITION() returns zero then zero; else subtract the result from the
string length.  Similarly, it's pretty easy to regexp away the
non-digits and measure the length of the resulting string.

I don't have a good feeling for whether these operations are common
enough to justify adding a few more functions.  They haven't yet come
up for me personally.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

```

### pgsql-hackers by date

 Next: From: Merlin Moncure Date: 2012-04-30 18:33:26 Subject: Re: Future In-Core Replication Previous: From: Robert Haas Date: 2012-04-30 18:07:26 Subject: Re: Patch: add conversion from pg_wchar to multibyte