Search Postgresql Archives

Division

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

 



I am having a problem gettig a percent via division. Below is the first
part of my trigger function where pct returns 0.00, instead of the
expected 0.50. If I try without dimensions to the numeric variable, I
just get 0. What is the correct way to accomplish the percent?

CREATE OR REPLACE FUNCTION "public"."issue" (varchar) RETURNS numeric
AS'
DECLARE
  repar text[];
  pct numeric(3,2);
  noreps integer;

BEGIN
  repar := string_to_array($1,''-'');
  noreps := array_upper(repar,1);
  pct := 1/noreps;
  RETURN pct;
END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

bachman=# select issue('AA-BB');
 issue
-------
  0.00
(1 row)



---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

[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