We have a table which consist of anonymous code/token which needs to be executed from procedure.
Here is the sample data:
Table:
create table tbl_tokens (id int,tokens text);
Record:
insert into tbl_tokens values(1,'do $$
declare id_cnt int;
begin
select count(1) into id_cnt
from emp
where id = $1;
if(id_cnt>0)
then
p_out := ''true'';
else
p_out := ''false'';
end if;
end;
$$');
Procedure:
CREATE OR REPLACE PROCEDURE public.prc_token(IN in_token public.tbl_tokens)
LANGUAGE plpgsql
AS
$procedure$
DECLARE v_out varchar(10);
BEGIN
execute(in_token.tokens) using 1,out v_out; --Executing anonymous code
if(v_out = 'true') then
raise info '1';
end if;
END;
$procedure$;
Procedure Call:
call public.prc_token(tbl_tokens);
Error:
ERROR: column "tbl_tokens" does not exist
LINE 2: call public.prc_token(tbl_tokens);
in_token, of type row of tabletbl_tokens. Anonymous blocks can't return values, so usingv_outto get a result fromEXECUTE(in_token.tokens)will not work.