Re: Add numeric_trim(numeric) - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: Add numeric_trim(numeric)
Date
Msg-id CAEZATCWTC+aHuoDw1do9kV5OLGCAfdQ=zwymwc2-x5j5axmGMw@mail.gmail.com
Whole thread Raw
In response to Re: Add numeric_trim(numeric)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 7 January 2016 at 00:11, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> A different approach is that I'm not real sure why we want a function
> that returns a modified numeric value at all.  To the extent I understood
> Marko's original use case, it seems like what you'd invariably do with the
> result is extract its scale().  Why not skip the middleman and define a
> function named something like minscale() or leastscale(), which returns an
> int that is the smallest scale that would not drop data?  (If you actually
> did want the modified numeric value, you could use round(x, minscale(x))
> to get it.)
>

minscale() sounds good to me.

Re-reading Marko's original use case, it sounds like that specific
example would boil down to a check that minscale(x) <= 2, although
that can be done today using trunc(x,2) = x. Still, it seems that
minscale() would be a useful general purpose function to have.

Regards,
Dean



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Add numeric_trim(numeric)
Next
From: Craig Ringer
Date:
Subject: Re: pglogical - logical replication contrib module