Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQuYW-0006Pv-CL for pgsql-general@arkaria.postgresql.org; Mon, 18 Dec 2017 12:30:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQuYV-0002nu-NL for pgsql-general@arkaria.postgresql.org; Mon, 18 Dec 2017 12:30:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eQuYV-0002nl-Cz for pgsql-general@lists.postgresql.org; Mon, 18 Dec 2017 12:30:03 +0000 Received: from host3.dynacom.ondsl.gr ([62.103.35.211] helo=smadev.internal.net) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eQuYR-000684-Ib for pgsql-general@lists.postgresql.org; Mon, 18 Dec 2017 12:30:02 +0000 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id vBICTuLc093256 for ; Mon, 18 Dec 2017 14:29:56 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: PostgreSQL needs percentage function To: pgsql-general@lists.postgresql.org References: <^75EF6A639D2C0E83BEC677FB95E668672BBAB816@walla.co.il> From: Achilleas Mantzios Message-ID: <146519cb-e622-1475-3457-2adee6b71f3a@matrix.gatewaynet.com> Date: Mon, 18 Dec 2017 14:29:56 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <^75EF6A639D2C0E83BEC677FB95E668672BBAB816@walla.co.il> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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