Search Postgresql Archives

Select of a function that returns a array

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

 



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

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@xxxxxxxxxxxxxx)


[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