I have an SQL query
SELECT c,d FROM tableX where a='str' AND b=var1 ;
I would like to substitute the var1 with a variable. I tried to use plpgsql.
CREATE OR REPLACE FUNCTION foo (var1 integer)
RETURNS TABLE (c integer, d varchar) AS
$BODY$
DECLARE
aa varchar = 'str';
BEGIN
RETURN QUERY EXECUTE
'SELECT c,d FROM tableX where a=aa AND b=@1' using var1;
END;
$BODY$
LANGUAGE plpgsql;
The error is
No operator matches the given name and argument type(s). You might need to add explicit type casts.