0

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?

Community
  • 1
  • 1
Balinti
  • 1,524
  • 1
  • 11
  • 14
  • I do not get the error you say that you see. Since you have a misnamed field in your function ("end" rather than "ende") I don't see how it can. Check you are calling the function you think you are. – Richard Huxton Mar 27 '16 at 19:54
  • @ Richard Huxton , thx for you mark. I corrected the question.. still the problem remains... it sais it did find the strt column. I am calling the right function... if I do not use execute stmt and write the query inside it works perfectly. – Balinti Mar 28 '16 at 08:35
  • I couldn't reproduce it here. Provide a complete script with dummy tables etc that reproduces the problem. – Richard Huxton Mar 28 '16 at 12:19

0 Answers0