Home:ALL Converter>PostgreSQL-dynamic sql inside function?

PostgreSQL-dynamic sql inside function?

Ask Time:2013-10-03T22:45:38         Author:user2843129

Json Formatter

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?

Author:user2843129,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19162226/postgresql-dynamic-sql-inside-function
yy