I have a query which takes stored query as text form a table and then run the specific query by user parameter. (in this case the parameter is name) The query goes:
CREATE OR REPLACE FUNCTION public.event_test(strt timestamp without time zone, ende timestamp without time zone, name character varying, world integer, type character varying, type_value integer)
RETURNS TABLE(user_code character varying, user_nick character varying, alliance character varying, delta bigint)
LANGUAGE plpgsql
AS $function$
DECLARE
stmt text;
BEGIN
select query into stmt from events_queries where event_name=name ;
return query execute stmt using strt,ende,world,type,type_value ;
END
$function$
When I am running it I get the error:
Column strt does not exist
even though I used execute with using
.
The function uses the parameter name
properly and if instead of using execute I write the query itself it goes fine as well.
I have looked at this similar problem : Pl/pgSQL there is no parameter $1 in EXECUTE statement
But the problems remains.
Any Idea how to pass the parameters inside my text?