Re: [SQL] Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function

2009-10-19 Thread Gary Chambers
> But if I read the OP correctly the sigma are in fact used additively in each > row in blah.  "sigma_* = sigma_* +" I apologize, but I omitted a CASE statement prior to each calculation of the values. The coefficients for each calculation change depending upon which case is valid. I could proba

Re: [SQL] Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function

2009-10-17 Thread Rob Sargent
But if I read the OP correctly the sigma are in fact used additively in each row in blah. "sigma_* = sigma_* +" matthias schoeneich wrote: Hi, as you don't seem to need the sigma_*'s, you could calc the whole result with one query using: CREATE OR REPLACE FUNCTION poly_example2() RETURNS S

Re: [SQL] Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function

2009-10-17 Thread matthias schoeneich
Hi, as you don't seem to need the sigma_*'s, you could calc the whole result with one query using: CREATE OR REPLACE FUNCTION poly_example2() RETURNS SETOF FLOAT8 AS $poly_example$ DECLARE f_result FLOAT8 := 0.0; i_rowcount INT:= 0 ; BEGIN SELECT sum((RANDOM() * 100 ) * (term

Re: [SQL] Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function

2009-10-16 Thread Rob Sargent
I don't see anything in the assignment statements (sigma_* :=) which would prevent one from doing all three of them within a single for loop. In fact, written as is there's some chance the values of the sigma_*s might change between repeated calls to the function since there is no explicit ord

[SQL] Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function

2009-10-16 Thread Gary Chambers
All... In the poly_example function below, I am emulating an actual requirement by querying the same table three (3) times in order to derive a solution to a problem. Is this the best or most efficient and effective way to implement this? The table (which consists of only five (5) FLOAT8 columns