Re: Re: PostgreSQL needs percentage function

From: Chris Travers <chris(dot)travers(at)gmail(dot)com>
To: Melvin Davidson <melvin6925(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Nick Dro <postgresql(at)walla(dot)co(dot)il>, Michael Nolan <htfoot(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Re: PostgreSQL needs percentage function
Date: 2017-12-20 15:06:27
Message-ID: CAKt_Zfv-v4Mt+p2m81GMSiXHPik2-sNYGDK6hPRKLPVS+u2YoA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you want one:

create or replace percent(numeric, numeric) returns numeric language sql as
$$ select ($1 / 100) * $2; $$;

On Tue, Dec 19, 2017 at 4:51 PM, Melvin Davidson <melvin6925(at)gmail(dot)com>
wrote:

>
>
> On Tue, Dec 19, 2017 at 4:54 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>>
>>
>> 2017-12-19 10:13 GMT+01:00 Nick Dro <postgresql(at)walla(dot)co(dot)il>:
>>
>>> This is exactly why I think there should be some build-in function for
>>> that...
>>> Percentage calculation exists in almost any databse and information
>>> system - it requires from use to implement many functions on thier own for
>>> something that is very basic.
>>> The general idea of my request is that postgresql should have build in
>>> function for percentage calculation it doesn't have to me the exact example
>>> I gave. Any thing will be better than none.
>>>
>>
>> I don't agree - there is not compatibility or portability reasons. The
>> calculation using numeric operators is pretty simple, and possibility to
>> create own function is here too.
>>
>> So there is not any reason to increase a postgresql catalogue.
>>
>> Please. don't do top post
>>
>> Regards
>>
>> Pavel
>>
>>
>>>
>>>
>>>
>>> ב דצמ׳ 18, 2017 18:28, Michael Nolan כתב:
>>>
>>>
>>>
>>> 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
>>>
>>>
>>
> >Percentage calculation exists in almost any databse and information
> system
>
> That is not exactly true. AFAIK, only Oracle has a Percentage function.
> SQL Server and MySQL do not.
> It has already been shown that it is just as easy to code percentage
> inline (EG: SELECT (50.8 x 5.2) / 100 AS pct; ## .026416
> as it is to call a function SELECT pct(50.8, 5.2);
> Please do not false statements to justify a request for a non-needed
> enhancement.
>
>
>
> --
> *Melvin Davidson*
> I reserve the right to fantasize. Whether or not you
> wish to share my fantasy is entirely up to you.
>

--
Best Wishes,
Chris Travers

Efficito: Hosted Accounting and ERP. Robust and Flexible. No vendor
lock-in.
http://www.efficito.com/learn_more

In response to

Browse pgsql-general by date

  From Date Subject
Next Message mark 2017-12-20 15:08:51 postgresql 9.5 has ocuuered OOM
Previous Message Merlin Moncure 2017-12-20 13:57:34 Re: Debugging a function - what's the best way to do this quickly?