Search Postgresql Archives

Re: Calculating percentages in Postgresql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Peter Nixonn wrote:
Hi Guys


Has anyone written a postgres function to calculate percentages without
giving "ERROR:  division by zero" when fed zeros?

Almost certainly. The question is, what do *you* want it to do?

You'll want to customise something like:

CREATE FUNCTION percent_plus(int4, int4) RETURNS int4 AS $$
  SELECT CASE WHEN $2=0 THEN -1 ELSE ($1*100)/$2 END;
$$ LANGUAGE SQL;

--
  Richard Huxton
  Archonet Ltd


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux