Re: PostgreSQL needs percentage function

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: PostgreSQL needs percentage function
Date: 2017-12-18 12:29:56
Message-ID: 146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 18/12/2017 14:23, Nick Dro 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

CREATE OR REPLACE FUNCTION percent(xall float,xper float) RETURNS float
    LANGUAGE sql IMMUTABLE STRICT
    AS $$ select xall * xper / 100.0 $$;

> 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?

--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Steele 2017-12-18 14:20:47 Re: PgBackRest question?
Previous Message Nick Dro 2017-12-18 12:23:38 PostgreSQL needs percentage function