PostgreSQL needs percentage function

Started by Nick Droover 8 years ago19 messagesgeneral
Jump to latest
#1Nick Dro
postgresql@walla.co.il

<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&lt;/div&gt;
<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>

#2Achilleas Mantzios
achill@matrix.gatewaynet.com
In reply to: Nick Dro (#1)
Re: PostgreSQL needs percentage function

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 reply to: Nick Dro (#1)
Re: PostgreSQL needs percentage function

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

#4Nick Dro
postgresql@walla.co.il
In reply to: hubert depesz lubaczewski (#3)
RE: Re: PostgreSQL needs percentage function

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

#5Geoff Winkless
pgsqladmin@geoff.dj
In reply to: Nick Dro (#4)
Re: Re: PostgreSQL needs percentage function

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

#6Pavel Stehule
pavel.stehule@gmail.com
In reply to: Nick Dro (#4)
Re: Re: PostgreSQL needs percentage function

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

Show quoted text

ב דצמ׳ 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

#7David G. Johnston
david.g.johnston@gmail.com
In reply to: Nick Dro (#4)
Re: Re: PostgreSQL needs percentage function

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.

#8Michael Nolan
htfoot@gmail.com
In reply to: Nick Dro (#1)
Re: PostgreSQL needs percentage function

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

#9Edson Carlos Ericksson Richter
richter@simkorp.com.br
In reply to: Michael Nolan (#8)
Re: PostgreSQL needs percentage function

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&gt;
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

#10David G. Johnston
david.g.johnston@gmail.com
In reply to: Edson Carlos Ericksson Richter (#9)
Re: PostgreSQL needs percentage function

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.​

#11Corey Taylor
corey.taylor.fl@gmail.com
In reply to: David G. Johnston (#10)
Re: PostgreSQL needs percentage function

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.

#12Edson Carlos Ericksson Richter
richter@simkorp.com.br
In reply to: David G. Johnston (#10)
Re: PostgreSQL needs percentage function

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.

#13Peter J. Holzer
hjp-pgsql@hjp.at
In reply to: Nick Dro (#4)
Re: Re: PostgreSQL needs percentage function

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/&gt;

#14Peter J. Holzer
hjp-pgsql@hjp.at
In reply to: David G. Johnston (#7)
Re: Re: PostgreSQL needs percentage function

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/&gt;

#15Nick Dro
postgresql@walla.co.il
In reply to: Peter J. Holzer (#14)
RE: Re: PostgreSQL needs percentage function

<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&quot; target="_blank" rel="noopener">https://www.postgresql.org/&lt;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>

#16Pavel Stehule
pavel.stehule@gmail.com
In reply to: Nick Dro (#15)
Re: Re: PostgreSQL needs percentage function

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

Show quoted text

ב דצמ׳ 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

#17Melvin Davidson
melvin6925@gmail.com
In reply to: Pavel Stehule (#16)
Re: Re: PostgreSQL needs percentage function

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.

#18Chris Travers
chris.travers@gmail.com
In reply to: Melvin Davidson (#17)
Re: Re: PostgreSQL needs percentage function

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

#19Nick Dro
postgresql@walla.co.il
In reply to: Chris Travers (#18)
RE: Re: Re: PostgreSQL needs percentage function

<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&quot; target="_blank" rel="noopener">https://www.postgresql.org/doc&lt;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%2Ftsmileys2%2F01.gif&amp;amp;scr=992bfd131feaa60d9df456ec5778dc98&quot; /></font></div>
</div>
</div>
</div>
</blockquote>
</blockquote>
</div></div>