I have a simple stored procedure below which is returning a SQL string:
CREATE OR REPLACE PROCEDURE dbo.select_users_test(sqlstring inout text)
LANGUAGE plpgsql
AS
$$
BEGIN
sqlstring = 'select * from dbo.user where usr_key in (1, 2);';
END;
$$;
I can call the stored procedure like this:
CALL dbo.select_users_test('')
and the result is :
sqlstring text |
---|
select * from dbo.user where usr_key in (1, 2); |
What I am trying to achieve is to execute that SQL string returned from the stored procedure.
I have tried
EXECUTE QUERY CALL dbo.select_users_test('');
and
EXECUTE CALL dbo.select_users_test('');
but both throw an error:
Syntax error at or near "CALL"
I am explicitly trying to achieve this with stored procedures and not functions, is it possible to execute the returned SQL string?
OUT
variables, which I'm pretty sure is not what you want. You will need to use a function.DO
can'tRETURN
anything either.