How would one construct PL code to call a function within a function dynamically?
I already have a method for doing this, but in my opinion, there has got to be a better way. Example...
CREATE OR REPLACE FUNCTION public.myfunction(schemaname text)
RETURNS int4 AS
$$
DECLARE
myrec record;
myval1 int4;
BEGIN
FOR myrec IN EXECUTE
'SELECT "' || myschema || '".myfunctioncall()
as myresult
FROM "' || myschema || '".mytable'
LOOP
END LOOP;
myval1 = myval1 + myrec.myresult;
RETURN myval1;
END; $$ LANGUAGE plpgsql;
As you can see, its a mess, but it will work. I am forced to use the FOR LOOP because the SELECT INTO does not support dynamically constructed string statements, and I am forced into using a SELECT statement and a FROM clause to call my function in the specified schema.
Any insight? Perhaps, I am just missing something really simple?
"Spock, help me..SPOCK!" -- Star Trek (original series)
Gary
gwinn7
I already have a method for doing this, but in my opinion, there has got to be a better way. Example...
CREATE OR REPLACE FUNCTION public.myfunction(schemaname text)
RETURNS int4 AS
$$
DECLARE
myrec record;
myval1 int4;
BEGIN
FOR myrec IN EXECUTE
'SELECT "' || myschema || '".myfunctioncall()
as myresult
FROM "' || myschema || '".mytable'
LOOP
END LOOP;
myval1 = myval1 + myrec.myresult;
RETURN myval1;
END; $$ LANGUAGE plpgsql;
As you can see, its a mess, but it will work. I am forced to use the FOR LOOP because the SELECT INTO does not support dynamically constructed string statements, and I am forced into using a SELECT statement and a FROM clause to call my function in the specified schema.
Any insight? Perhaps, I am just missing something really simple?
"Spock, help me..SPOCK!" -- Star Trek (original series)
Gary
gwinn7