| From: | Robert Fitzpatrick <lists(at)webtent(dot)net> | 
|---|---|
| To: | PostgreSQL <pgsql-general(at)postgresql(dot)org> | 
| Subject: | Division | 
| Date: | 2005-11-04 17:13:39 | 
| Message-ID: | 1131124419.22487.49.camel@columbus.webtent.org | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
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)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tino Wildenhain | 2005-11-04 17:39:24 | Re: Division | 
| Previous Message | Tom Lane | 2005-11-04 16:53:22 | Re: Bug in Role support? |