Re: Add numeric_trim(numeric)

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add numeric_trim(numeric)
Date: 2016-01-07 08:10:06
Message-ID: CAEZATCWTC+aHuoDw1do9kV5OLGCAfdQ=zwymwc2-x5j5axmGMw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7 January 2016 at 00:11, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2016-01-07 08:28:17 Re: pglogical - logical replication contrib module
Previous Message Pavel Stehule 2016-01-07 08:02:27 Re: Add numeric_trim(numeric)