reading about how to make an SP that returns the results of a query it seems I must do this kind of thing (from tutorial site)
CREATE OR REPLACE FUNCTION show_cities() RETURNS refcursor AS $$
DECLARE
ref refcursor; -- Declare a cursor variable
BEGIN
OPEN ref FOR SELECT city, state FROM cities; -- Open a cursor
RETURN ref; -- Return the cursor to the caller
END;
$$ LANGUAGE plpgsql;
OK, I get this, but I want to pass the SQL in as a paramter so I need to do (I think)
EXECUTE mysql ......
But I dont see how to make EXECUTE
return a cursor
EDIT:
OK now I see that I misunderstood what the non dynamic case does. I expected to be able to do select show_cities()
and have it do that same thing as SELECT city, state FROM cities
, it does not. Of course now that I think about it this isnt surprising. I want to return the actual set of records.