1

I have a PostgreSQL function that takes one string as parameter/this is dynamic sql query/ and executes that dynamic SQL and I expect the result from the dynamic query.

It seems that in PostgreSQL I should predefine what I will return - but this is impossible since I am executing dynamic statement and sometimes I will return one int column, sometimes I will return 5 varchar columns....

Another thing is that existing jdbc code will call the function-and I cannot change it-I can't define the types dynamically like:

{call execute_dynamic(?) as (a varchar(255),b int)};

The code that will call the procedure is: 

{call execute_dynamic(?)}

and cannot be changed....

Is there a way to implement this?

1 Answer 1

1

The solution is to use refcursor as return type.

OPEN ref_cursor FOR EXECUTE dynamic_sql;
 return ref_cursor;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.