pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PostgreSQL needs percentage function
19+ messages / 12 participants
[nested] [flat]

* PostgreSQL needs percentage function
@ 2017-12-18 12:23  Nick Dro <postgresql@walla.co.il>
  0 siblings, 3 replies; 19+ messages in thread

From: Nick Dro @ 2017-12-18 12:23 UTC (permalink / raw)
  To: pgsql-general

<div dir='rtl'><div dir="ltr">Hi,</div>
<div dir="ltr">Why PostgreSQL doesn't have build-in function to calculate percentage? somthing like percent(number,%</div>
<div dir="ltr">for example:</div>
<div dir="ltr">select percent(100,1) will calculate 1% of 100 = 1</div>
<div dir="ltr">select percent(25,20) will calculate 20% of 25 = 5</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">Seems like a nice addition to the math functions list:</div>
<div dir="ltr">https://www.postgresql.org/docs/9.5/static/functions-math.html</div;
<div dir="ltr">&nbsp;</div>
<div dir="ltr">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.</div>
<div dir="ltr">Seems like easy to implment isn't it?</div></div>




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: PostgreSQL needs percentage function
@ 2017-12-18 12:29  Achilleas Mantzios <achill@matrix.gatewaynet.com>
  parent: Nick Dro <postgresql@walla.co.il>
  2 siblings, 0 replies; 19+ messages in thread

From: Achilleas Mantzios @ 2017-12-18 12:29 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: PostgreSQL needs percentage function
@ 2017-12-18 15:44  hubert depesz lubaczewski <depesz@depesz.com>
  parent: Nick Dro <postgresql@walla.co.il>
  2 siblings, 0 replies; 19+ messages in thread

From: hubert depesz lubaczewski @ 2017-12-18 15:44 UTC (permalink / raw)
  To: Nick Dro <postgresql@walla.co.il>; +Cc: pgsql-general

On Mon, Dec 18, 2017 at 02:23:38PM +0200, 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

What is the problem with using normal multiplication for this?

depesz




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

*  RE:  Re: PostgreSQL needs percentage function
@ 2017-12-18 16:13  Nick Dro <postgresql@walla.co.il>
  0 siblings, 4 replies; 19+ messages in thread

From: Nick Dro @ 2017-12-18 16:13 UTC (permalink / raw)
  To: depesz@depesz.com; pgsql-general; +Cc: pgsql-general

<div><div dir="rtl"><div dir="ltr"><br>
<div dir="ltr">Hi,</div>
<div dir="ltr">I know how to implement this. It's not the issue.</div>
<div dir="ltr">It's very easy to implement absolute value as well yet still PostgreSQL gives <tt><code>abs(<tt>x</tt>)</code></tt> function which is build in function.</div>
<div dir="ltr">My claim is that if there is a build in function for absolute value why not for percentage? Both are very basic mathematical operations.</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">Can you give a good reason why absolute value has a build in function while percentage is not?</div>
</div></div><section class="cust_msg_end"></section><blockquote style="margin:0;margin-bottom:20px;border-top:1px solid #e0e0e0;"><br>ב דצמ׳ 18, 2017 17:44, hubert depesz lubaczewski כתב:<blockquote style="margin:0;margin-bottom:20px;border-top:1px solid #e0e0e0">On Mon, Dec 18, 2017 at 02:23:38PM +0200, Nick Dro wrote:
<br>&gt;    Hi,
<br>&gt;    Why PostgreSQL doesn't have build-in function to calculate percentage?
<br>&gt;    somthing like percent(number,%
<br>&gt;    for example:
<br>&gt;    select percent(100,1) will calculate 1% of 100 = 1
<br>&gt;    select percent(25,20) will calculate 20% of 25 = 5
<br>What is the problem with using normal multiplication for this?
<br>depesz<br></blockquote></blockquote><br></div>




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-18 16:17  Geoff Winkless <pgsqladmin@geoff.dj>
  parent: Nick Dro <postgresql@walla.co.il>
  3 siblings, 0 replies; 19+ messages in thread

From: Geoff Winkless @ 2017-12-18 16:17 UTC (permalink / raw)
  To: postgresql@walla.co.il; +Cc: depesz@depesz.com; pgsql-general

On 18 December 2017 at 16:13, Nick Dro <postgresql@walla.co.il> wrote:
> Can you give a good reason why absolute value has a build in function while
> percentage is not?


ABS is an ansi-standard SQL function.

Geoff




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-18 16:19  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Nick Dro <postgresql@walla.co.il>
  3 siblings, 0 replies; 19+ messages in thread

From: Pavel Stehule @ 2017-12-18 16:19 UTC (permalink / raw)
  To: Nick Dro <postgresql@walla.co.il>; +Cc: hubert depesz lubaczewski <depesz@depesz.com>; pgsql-general

2017-12-18 17:13 GMT+01:00 Nick Dro <postgresql@walla.co.il>:

>
> Hi,
> I know how to implement this. It's not the issue.
> It's very easy to implement absolute value as well yet still PostgreSQL
> gives abs(x) function which is build in function.
> My claim is that if there is a build in function for absolute value why
> not for percentage? Both are very basic mathematical operations.
>
> Can you give a good reason why absolute value has a build in function
> while percentage is not?
>

probably history

abs is some basic functions - the implementation is not primitive. Percent
function is maybe in spreadsheets, but I don't remember this function from
any classic language - more it can be simply implemented by numeric
operators.

In this case, I am not a fan of this functions, you can write just 25 *
0.20

Regards

Pavel


>
> ב דצמ׳ 18, 2017 17:44, hubert depesz lubaczewski כתב:
>
> On Mon, Dec 18, 2017 at 02:23:38PM +0200, 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
> What is the problem with using normal multiplication for this?
> depesz
>
>
>

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-18 16:21  David G. Johnston <david.g.johnston@gmail.com>
  parent: Nick Dro <postgresql@walla.co.il>
  3 siblings, 1 reply; 19+ messages in thread

From: David G. Johnston @ 2017-12-18 16:21 UTC (permalink / raw)
  To: Nick Dro <postgresql@walla.co.il>; +Cc: Hubert Lubaczewski <depesz@depesz.com>; pgsql-general

On Mon, Dec 18, 2017 at 9:13 AM, Nick Dro <postgresql@walla.co.il> wrote:

>
> Hi,
> I know how to implement this. It's not the issue.
> It's very easy to implement absolute value as well yet still PostgreSQL
> gives abs(x) function which is build in function.
> My claim is that if there is a build in function for absolute value why
> not for percentage? Both are very basic mathematical operations.
>
> Can you give a good reason why absolute value has a build in function
> while percentage is not?
>

Frankly, the name "percent​" is a poor choice: am I supposed to input two
number and it gives me the percentage that the first is of the second
(division) or, at you think here, I input a number and a percentage to
multiply them?  And why is percent >1 as opposed to (generally) between 0
and 1?

abs(x) has only one input and so none of those questions apply to it.

David J.

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: PostgreSQL needs percentage function
@ 2017-12-18 16:28  Michael Nolan <htfoot@gmail.com>
  parent: Nick Dro <postgresql@walla.co.il>
  2 siblings, 1 reply; 19+ messages in thread

From: Michael Nolan @ 2017-12-18 16:28 UTC (permalink / raw)
  To: Nick Dro <postgresql@walla.co.il>; +Cc: pgsql-general

On Mon, Dec 18, 2017 at 6:23 AM, Nick Dro <postgresql@walla.co.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

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: PostgreSQL needs percentage function
@ 2017-12-18 16:56  Edson Carlos Ericksson Richter <richter@simkorp.com.br>
  parent: Michael Nolan <htfoot@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Edson Carlos Ericksson Richter @ 2017-12-18 16:56 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org


Em 18/12/2017 14:28, Michael Nolan escreveu:
>
>
> On Mon, Dec 18, 2017 at 6:23 AM, Nick Dro <postgresql@walla.co.il 
> <mailto:postgresql@walla.co.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
>     <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

I believe that having a built-in function for percentage is not a good 
idea. Is just like having a function to calculate fractions... Someone 
would like to have percentages as 0..1, others would like to have it 
multiplied by 100. How to deal with integers? And so on (as others 
already stated here).

But, is it possible to have a aggregate function that calculates de 
percent from the sum (and/or count) total (as a value from 0 ... 1) for 
numeric (or double)?

Looking really superficially seems to me that would be a great addition 
to the aggreggates (and is not just a trivial div/multiply op)


Edson

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: PostgreSQL needs percentage function
@ 2017-12-18 17:01  David G. Johnston <david.g.johnston@gmail.com>
  parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
  0 siblings, 2 replies; 19+ messages in thread

From: David G. Johnston @ 2017-12-18 17:01 UTC (permalink / raw)
  To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: pgsql-general@lists.postgresql.org

On Mon, Dec 18, 2017 at 9:56 AM, Edson Carlos Ericksson Richter <
richter@simkorp.com.br> wrote:

> But, is it possible to have a aggregate function that calculates de
> percent from the sum (and/or count) total (as a value from 0 ... 1) for
> numeric (or double)?
>

​Do you mean:

SELECT id, val, val / (sum(val) OVER ())
FROM vals;​

​David J.​

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: PostgreSQL needs percentage function
@ 2017-12-18 17:07  Corey Taylor <corey.taylor.fl@gmail.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 19+ messages in thread

From: Corey Taylor @ 2017-12-18 17:07 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org

On Mon, Dec 18, 2017 at 11:01 AM, David G. Johnston <
david.g.johnston@gmail.com> wrote:

> ​Do you mean:
>
> SELECT id, val, val / (sum(val) OVER ())
> FROM vals;​
>


You could end up with a percentage > 100 or divide by 0 with that if the
values are not in a proper range.  I don't know if that would be the
intention.

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: PostgreSQL needs percentage function
@ 2017-12-18 17:08  Edson Carlos Ericksson Richter <richter@simkorp.com.br>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 19+ messages in thread

From: Edson Carlos Ericksson Richter @ 2017-12-18 17:08 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general@lists.postgresql.org


Em 18/12/2017 15:01, David G. Johnston escreveu:
> On Mon, Dec 18, 2017 at 9:56 AM, Edson Carlos Ericksson Richter 
> <richter@simkorp.com.br <mailto:richter@simkorp.com.br>>wrote:
>
>     But, is it possible to have a aggregate function that calculates
>     de percent from the sum (and/or count) total (as a value from 0
>     ... 1) for numeric (or double)?
>
>
> ​Do you mean:
>
> SELECT id, val, val / (sum(val) OVER ())
> FROM vals;​
>
> ​David J.​
>

I've never thought about Window Functions that way.
Thanks, it is enligthning.

:-)

Regards,

Edson.

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-18 19:30  Peter J. Holzer <hjp-pgsql@hjp.at>
  parent: Nick Dro <postgresql@walla.co.il>
  3 siblings, 0 replies; 19+ messages in thread

From: Peter J. Holzer @ 2017-12-18 19:30 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2017-12-18 18:13:58 +0200, Nick Dro wrote:
> I know how to implement this. It's not the issue.
> It's very easy to implement absolute value as well yet still PostgreSQL gives
> abs(x) function which is build in function.
> My claim is that if there is a build in function for absolute value why not for
> percentage? Both are very basic mathematical operations.

Apart from historic reasons, abs(x) is actually quite awkward to
write inline: You need to write x 3 times:

case when x >= 0 then x else -x end

Which is already quite a bit longer than abs(x), but it gets worse when
x is a complicated expression:

    abs((graph_width + graph_border_width) / pixels_per_character)
becomes
    case
        when ((graph_width + graph_border_width) / pixels_per_character) >= 0
        then ((graph_width + graph_border_width) / pixels_per_character)
        else -((graph_width + graph_border_width) / pixels_per_character)
    end

And the expression is evaluated twice, which is a problem if is contains
a function call with a side effekt. abs(random()*3-1) is not the same as
case random()*3-1 >= 0 then random()*3-1 else -(random()*3-1) end.

So while primitive, abs() is actually useful as a function.

percent(a, b) isn't even shorter than (a * b / 100), and it doesn't get
better for more complicated expressions. It' just less readable (does
percent(a, b) mean (a * b / 100) or (a / b * 100) or (b / a * 100)? Is
there even a factor of 100 involved? (Is should be, because that's what
"cent" means, but it's missing in percent_rank()). If such a function
existed, I would avoid it.

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/;

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-18 19:35  Peter J. Holzer <hjp-pgsql@hjp.at>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 19+ messages in thread

From: Peter J. Holzer @ 2017-12-18 19:35 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2017-12-18 09:21:49 -0700, David G. Johnston wrote:
> Frankly, the name "percent" is a poor choice:
[...]
> And why is percent >1 as opposed to (generally) between 0 and 1?

That's what "per cent" means: "of hundred". The whole is 100. If the
whole is 1, it's not a percentage (and yes, percent_rank() is misnamed).

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/;

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

*  RE:  Re: PostgreSQL needs percentage function
@ 2017-12-19 09:13  Nick Dro <postgresql@walla.co.il>
  0 siblings, 1 reply; 19+ messages in thread

From: Nick Dro @ 2017-12-19 09:13 UTC (permalink / raw)
  To: htfoot@gmail.com; pgsql-general; +Cc: pgsql-general

<div dir='rtl'><div>
<div dir="rtl">
<div dir="ltr">This is exactly why I think there should be some build-in function for that...</div>
<div dir="ltr">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.</div>
<div dir="ltr">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.</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">&nbsp;</div>
</div>
<section class="cust_msg_end"></section>
<blockquote style="margin: 0; margin-bottom: 20px; border-top: 1px solid #e0e0e0;"><br />ב דצמ׳ 18, 2017 18:28, Michael Nolan כתב:
<blockquote style="margin: 0; margin-bottom: 20px; border-top: 1px solid #e0e0e0;">
<div dir="ltr"><br />
<div><br />
<div>On Mon, Dec 18, 2017 at 6:23 AM, Nick Dro <span dir="ltr">&lt;<a href="mailto:postgresql@walla.co.il" target="_blank" rel="noopener">postgresql@walla.co.il </a>&gt;</span> wrote:<br />
<blockquote style="margin: 0 0 0 .8ex; border-left: 1px #ccc solid; padding-left: 1ex;">
<div dir="rtl">
<div dir="ltr">Hi,</div>
<div dir="ltr">Why PostgreSQL doesn't have build-in function to calculate percentage? somthing like percent(number,%</div>
<div dir="ltr">for example:</div>
<div dir="ltr">select percent(100,1) will calculate 1% of 100 = 1</div>
<div dir="ltr">select percent(25,20) will calculate 20% of 25 = 5</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">Seems like a nice addition to the math functions list:</div>
<div dir="ltr"><a href="https://www.postgresql.org/docs/9.5/static/functions-math.html"; target="_blank" rel="noopener">https://www.postgresql.org/<wbr />docs/9.5/static/functions-<wbr />math.html</a></div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">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.</div>
<div dir="ltr">Seems like easy to implment isn't it?</div>
</div>
</blockquote>
</div>
</div>
<div>&nbsp;</div>
<div>It's a bit trickier than that, because you';ll have to deal with integers, real, double precision, etc.&nbsp; You may also want to deal with null values.&nbsp; 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.</div>
<div>--</div>
<div>Mike Nolan</div>
</div>
</blockquote>
</blockquote>
</div></div>




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-19 09:54  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Nick Dro <postgresql@walla.co.il>
  0 siblings, 1 reply; 19+ messages in thread

From: Pavel Stehule @ 2017-12-19 09:54 UTC (permalink / raw)
  To: Nick Dro <postgresql@walla.co.il>; +Cc: Michael Nolan <htfoot@gmail.com>; pgsql-general

2017-12-19 10:13 GMT+01:00 Nick Dro <postgresql@walla.co.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@walla.co.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
>
>

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-19 15:51  Melvin Davidson <melvin6925@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Melvin Davidson @ 2017-12-19 15:51 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Nick Dro <postgresql@walla.co.il>; Michael Nolan <htfoot@gmail.com>; pgsql-general

On Tue, Dec 19, 2017 at 4:54 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

>
>
> 2017-12-19 10:13 GMT+01:00 Nick Dro <postgresql@walla.co.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@walla.co.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.

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: Re: PostgreSQL needs percentage function
@ 2017-12-20 15:06  Chris Travers <chris.travers@gmail.com>
  parent: Melvin Davidson <melvin6925@gmail.com>
  0 siblings, 0 replies; 19+ messages in thread

From: Chris Travers @ 2017-12-20 15:06 UTC (permalink / raw)
  To: Melvin Davidson <melvin6925@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; Nick Dro <postgresql@walla.co.il>; Michael Nolan <htfoot@gmail.com>; 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@gmail.com>
wrote:

>
>
> On Tue, Dec 19, 2017 at 4:54 AM, Pavel Stehule <pavel.stehule@gmail.com>
> wrote:
>
>>
>>
>> 2017-12-19 10:13 GMT+01:00 Nick Dro <postgresql@walla.co.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@walla.co.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

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

*  RE:  Re: Re: PostgreSQL needs percentage function
@ 2017-12-20 16:32  Nick Dro <postgresql@walla.co.il>
  0 siblings, 0 replies; 19+ messages in thread

From: Nick Dro @ 2017-12-20 16:32 UTC (permalink / raw)
  To: melvin6925@gmail.com; pavel.stehule@gmail.com; htfoot@gmail.com; pgsql-general; +Cc: Michael Nolan <htfoot@gmail.com>; pgsql-general

<div dir='rtl'><div>
<div dir="rtl">
<div dir="ltr">&nbsp;I said: "Percentage calculation exists in almost any databse and information system"<br /><br /></div>
<div dir="ltr">I didn't say it exists in any <span class="st">RDB</span>. I meant that any system that is using databse like information system uses percentace calculation therefor if most of the users of the databse need such function it make sence to have it in it's base code - ready for use rather than ask each one to implment his own.</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">&nbsp;</div>
</div>
<section class="cust_msg_end"></section>
<blockquote style="margin: 0; margin-bottom: 20px; border-top: 1px solid #e0e0e0;"><br />ב דצמ׳ 19, 2017 17:51, Melvin Davidson כתב:
<blockquote style="margin: 0; margin-bottom: 20px; border-top: 1px solid #e0e0e0;">
<div dir="ltr"><br />
<div><br />
<div>On Tue, Dec 19, 2017 at 4:54 AM, Pavel Stehule <span dir="ltr">&lt;<a href="mailto:pavel.stehule@gmail.com" target="_blank" rel="noopener">pavel.stehule@gmail.com </a>&gt;</span> wrote:<br />
<blockquote style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;">
<div dir="ltr"><br />
<div><br />
<div>2017-12-19 10:13 GMT+01:00 Nick Dro <span dir="ltr">&lt;<a href="mailto:postgresql@walla.co.il" target="_blank" rel="noopener">postgresql@walla.co.il </a>&gt;</span>:<br />
<blockquote style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;">
<div dir="rtl">
<div>
<div dir="rtl">
<div dir="ltr">This is exactly why I think there should be some build-in function for that...</div>
<div dir="ltr">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.</div>
<div dir="ltr">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.</div>
</div>
</div>
</div>
</blockquote>
<div>&nbsp;</div>
<div>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.</div>
<div>&nbsp;</div>
<div>So there is not any reason to increase a postgresql catalogue.</div>
<div>&nbsp;</div>
<div>Please. don't do top post</div>
<div>&nbsp;</div>
<div>Regards</div>
<div>&nbsp;</div>
<div>Pavel</div>
<div>&nbsp;</div>
<blockquote style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;">
<div dir="rtl">
<div>
<div dir="rtl">
<div dir="ltr">&nbsp;</div>
<div dir="ltr">&nbsp;</div>
</div>
<section></section>
<blockquote style="margin: 0px 0px 20px; border-top: 1px solid #e0e0e0;"><br />ב דצמ׳ 18, 2017 18:28, Michael Nolan כתב:
<blockquote style="margin: 0px 0px 20px; border-top: 1px solid #e0e0e0;">
<div dir="ltr"><br />
<div><br />
<div>On Mon, Dec 18, 2017 at 6:23 AM, Nick Dro <span dir="ltr">&lt;<a href="mailto:postgresql@walla.co.il" target="_blank" rel="noopener">post= &lt; gresql@walla.co.il </a>&gt;</span> wrote:<br />
<blockquote style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;">
<div dir="rtl">
<div dir="ltr">Hi,</div>
<div dir="ltr">Why PostgreSQL doesn't have build-in function to calculate percentage? somthing like percent(number,%</div>
<div dir="ltr">for example:</div>
<div dir="ltr">select percent(100,1) will calculate 1% of 100 = 1</div>
<div dir="ltr">select percent(25,20) will calculate 20% of 25 = 5</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">Seems like a nice addition to the math functions list:</div>
<div dir="ltr"><a href="https://www.postgresql.org/docs/9.5/static/functions-math.html"; target="_blank" rel="noopener">https://www.postgresql.org/doc<wbr />s/9.5/static/functions-math.ht<wbr />ml</a></div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">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.</div>
<div dir="ltr">Seems like easy to implment isn't it?</div>
</div>
</blockquote>
</div>
</div>
<div>&nbsp;</div>
<div>It's a bit trickier than that, because you';ll have to deal with integers, real, double precision, etc.&nbsp; You may also want to deal with null values.&nbsp; 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.</div>
<div>--</div>
<div>Mike Nolan</div>
</div>
</blockquote>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<br />&gt;Percentage calculation exists in almost any databse and information system</div>
<div>&nbsp;</div>
<div>That is not exactly true. AFAIK, only Oracle has a Percentage function. SQL Server and MySQL do not. </div>
<div>It has already been shown that it is just as easy to code percentage inline&nbsp; (EG: SELECT (50.8 x 5.2) / 100 AS pct;&nbsp;&nbsp; ## .026416 </div>
<div>as it is to call a function SELECT pct(50.8, 5.2); </div>
<div>Please do not false statements to justify a request for a non-needed enhancement.</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>-- <br />
<div>
<div dir="ltr"><font size="4"><b><span style="font-family: courier new,monospace;">Melvin Davidson</span></b></font><br /><font style="font-weight: bold;" size="3"><span style="color: #8000ff;">I reserve the right to fantasize.&nbsp; Whether or not you </span><br style="color: #8000ff;" /> <span style="color: #8000ff;">wish to share my fantasy is entirely up to you. </span><img style="color: #8000ff;" src="https://api-mail.walla.co.il/proxy?url=http%3A%2F%2Fus.i1.yimg.com%2Fus.yimg.com%2Fi%2Fmesg%2Ftsmile...; /></font></div>
</div>
</div>
</div>
</blockquote>
</blockquote>
</div></div>




^ permalink  raw  reply  [nested|flat] 19+ messages in thread


end of thread, other threads:[~2017-12-20 16:32 UTC | newest]

Thread overview: 19+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-12-18 12:23 PostgreSQL needs percentage function Nick Dro <postgresql@walla.co.il>
2017-12-18 12:29 ` Achilleas Mantzios <achill@matrix.gatewaynet.com>
2017-12-18 15:44 ` hubert depesz lubaczewski <depesz@depesz.com>
2017-12-18 16:28 ` Michael Nolan <htfoot@gmail.com>
2017-12-18 16:56   ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-18 17:01     ` David G. Johnston <david.g.johnston@gmail.com>
2017-12-18 17:07       ` Corey Taylor <corey.taylor.fl@gmail.com>
2017-12-18 17:08       ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-18 16:13  RE:  Re: PostgreSQL needs percentage function Nick Dro <postgresql@walla.co.il>
2017-12-18 16:17 ` Geoff Winkless <pgsqladmin@geoff.dj>
2017-12-18 16:19 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-12-18 16:21 ` David G. Johnston <david.g.johnston@gmail.com>
2017-12-18 19:35   ` Peter J. Holzer <hjp-pgsql@hjp.at>
2017-12-18 19:30 ` Peter J. Holzer <hjp-pgsql@hjp.at>
2017-12-19 09:13  RE:  Re: PostgreSQL needs percentage function Nick Dro <postgresql@walla.co.il>
2017-12-19 09:54 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-12-19 15:51   ` Melvin Davidson <melvin6925@gmail.com>
2017-12-20 15:06     ` Chris Travers <chris.travers@gmail.com>
2017-12-20 16:32  RE:  Re: Re: PostgreSQL needs percentage function Nick Dro <postgresql@walla.co.il>

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