The following bug has been logged online:
Bug reference: 5549
Logged by: David Schmitt
Email address: david@dasz.at
PostgreSQL version: 8 and 9
Operating system: n/a
Description: Feature: plpgsql should allow DECLARE cursor FOR EXECUTE
'...'
Details:
This is not implemented:
---------------------------------------------------------------------
CREATE OR REPLACE FUNCTION foo(tbl text) RETURNS void AS
$BODY$
DECLARE
working_cursor NO SCROLL CURSOR FOR EXECUTE $$SELECT something $$ || tbl
|| $$ ... $$;
BEGIN
FOR rec IN working_cursor LOOP
-- ...
END LOOP;
END$BODY$
LANGUAGE 'plpgsql' VOLATILE;
---------------------------------------------------------------------
The obvious workaround is hand-coding the LOOP with OPEN ... FOR EXECUTE and
manual FETCHing, but it would be great to have this missing piece supported
in syntax and avoid duplicating the error-prone hand-coding.
Thanks for your time and work!