From: | Michael Nolan <htfoot(at)gmail(dot)com> |
---|---|
To: | Nick Dro <postgresql(at)walla(dot)co(dot)il> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: PostgreSQL needs percentage function |
Date: | 2017-12-18 16:28:53 |
Message-ID: | CAOzAquL87kw2cKjqxDkevpx+0T5-m1andw2PPK5Vf0qUqmr5fA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Dec 18, 2017 at 6:23 AM, Nick Dro <postgresql(at)walla(dot)co(dot)il> wrote:
> Hi,
> Why PostgreSQL doesn't have build-in function to calculate percentage?
> somthing like percent(number,%
> for example:
> select percent(100,1) will calculate 1% of 100 = 1
> select percent(25,20) will calculate 20% of 25 = 5
>
> Seems like a nice addition to the math functions list:
> https://www.postgresql.org/docs/9.5/static/functions-math.html
>
> This is veryhelpull function, many uses percentage calculation in thier
> work and it will simplify the process. Percentage calculation is considered
> a basic math operation and I think postgresql should support it as a
> build-in function.
> Seems like easy to implment isn't it?
>
It's a bit trickier than that, because you';ll have to deal with integers,
real, double precision, etc. You may also want to deal with null values.
I found it more useful to write a function that displays X as a percentage
of Y, rounded to 1 digit to the right of the decimal point.
--
Mike Nolan
From | Date | Subject | |
---|---|---|---|
Next Message | Edson Carlos Ericksson Richter | 2017-12-18 16:56:49 | Re: PostgreSQL needs percentage function |
Previous Message | David G. Johnston | 2017-12-18 16:21:49 | Re: Re: PostgreSQL needs percentage function |