0

I get following error from the function below:

ERROR:  column "_df" does not exist  

create or replace function lax()returns setof record as
$$
declare 
  rs record;
  _planunitcode int;
  _DF VARCHAR(25);
  str text;
begin
  _planunitcode:=1;
  _DF :='role.planner';
  str :='select role from userplanunit where role = _DF';
  --str :='select role from userplanunit where role = quote_literal('DF');';quote_ident
  for rs in execute str
  --for rs in select role from userplanunit where role = _DF
  loop
    return next rs;
  end loop;
  return;
end
$$ language 'plpgsql';

1 Answer 1

1

i rectified it is the problem of escaping the single quote

CREATE OR replace FUNCTION lax ()
RETURNS setof record AS $$

DECLARE rs record;

_planunitcode INT;

_DF VARCHAR(25);

str TEXT;

BEGIN
    _planunitcode: = 1;

    _DF : = 'role.planner';

    str : = 'select role from userplanunit where role ='''||_DF||'''';
    FOR

    rs IN

    EXECUTE str LOOP

    RETURN NEXT rs;
END

LOOP;

RETURN;END $$

LANGUAGE 'plpgsql';
Sign up to request clarification or add additional context in comments.

1 Comment

THANK YOU i got it and using in my project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.