I want to check the results of a Postgres function (changing a function is not possible).
The function takes REFCURSOR and several other things as arguments and returns the same RECURSOR.
get_function_that_returns_cursor(ret, 4100, 'SOMETHING', 123465)
Now I want to create a little test in Postgres to get the results of this FUNCTION. Something like the code below (this is my approach, but it does not work):
DO $$ DECLARE ret REFCURSOR; row_to_read table_it_will_return%ROWTYPE ; BEGIN PERFORM get_function_that_returns_cursor(ret, 4100, 'SOMETHING', 123465); -- OR SELECT get_function_that_returns_cursor(ret, 4100, 'SOMETHING', 123465) INTO ret FOR row_to_read IN SELECT * FROM ret LOOP -- (...) RAISE NOTICE 'Row read...'; END LOOP; CLOSE ret; END $$;
Any suggestion on how to make this work? A general solution that can be used to test this type of function (which get the cursor and return the cursor?
And if we do not know the returned rowtype, how can we do this?
What is the best way to debug things like this in PostgresQL
RGPT
source share