Syntax Error In Postgresql Function
You want RETURN QUERY EXECUTE for dynamic SQL.

With RETURN QUERY you're trying to use a string literal as the start of a query. That's nonsensical and raises a syntax error.

Also, use format with the %I and %L specifiers for identifiers and literals, instead of using concatenation. Otherwise you have SQL injection issues in your function.