From: | Listas Evandro (Não use este endereço para mensagens pessoais) <listasjr(at)gmail(dot)com> |
---|---|
To: | pgsql-sql <pgsql-sql(at)postgresql(dot)org> |
Subject: | Select of a function that returns a array |
Date: | 2005-05-05 14:38:29 |
Message-ID: | ffac568905050507383026a00b@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-sql |
Hi guys
I'm trying to figure out a way to make this select work even for a wrong value:
select mean_and_variancepop('golf', 'temperature');
or
select CAST (mean_and_variancepop('golf', 'temperature') AS float(2));
This function return an array
the function is:
CREATE or replace FUNCTION mean_and_variancepop(var_table varchar,
var_col varchar) RETURNS float(2) AS $$
DECLARE
curs refcursor;
a float;
b float;
c float;
retvals float[2];
sum float:=0;
BEGIN
open curs FOR EXECUTE 'SELECT ' || quote_ident(var_col) || ' FROM
' || quote_ident(var_table);
b:=0;
LOOP
-- some computations
FETCH curs INTO a;
IF NOT FOUND THEN
EXIT; -- exit loop
END IF;
b:=b+1;
c:=a;
sum:= sum + c;
END LOOP;
CLOSE curs;
retvals[0]:= sum / b;
retvals[1] :=4;
RETURN retvals;
END;
$$ LANGUAGE plpgsql;
Thanks
-Jr
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2005-05-05 14:52:31 | Re: postgresql replication |
Previous Message | Peter Wilson | 2005-05-05 14:35:27 | Slony v. DBMirror |
From | Date | Subject | |
---|---|---|---|
Next Message | a3a18850 | 2005-05-05 17:58:04 | Re: HELP: aggregating insert rule for multirow inserts. |
Previous Message | Listas Evandro (Não use este endereço para mensagens pessoais) | 2005-05-05 14:27:58 | Select of a function that returns a array |