pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: PostgreSQL needs percentage function
Date: Mon, 18 Dec 2017 14:29:56 +0200
Message-ID: <146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com> (raw)
In-Reply-To: <^75EF6A639D2C0E83BEC677FB95E668672BBAB816@walla.co.il>
References: <^75EF6A639D2C0E83BEC677FB95E668672BBAB816@walla.co.il>

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





view thread (19+ messages)  latest in thread

Message-ID: <146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com>
Permalink:  ../146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: achill@matrix.gatewaynet.com
  Subject: Re: PostgreSQL needs percentage function
  In-Reply-To: <146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com>
  References: <^75EF6A639D2C0E83BEC677FB95E668672BBAB816@walla.co.il> <146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox