Here's my code:
CREATE OR REPLACE FUNCTION public.view_columns_f(viewname text)
RETURNS TABLE(columnn_name text, data_type text)
LANGUAGE plpgsql
AS $function$
BEGIN
return query execute
$$SELECT attname, format_type(atttypid, atttypmod) AS data_type
FROM pg_attribute
WHERE attrelid = '$1'::regclass$$
using viewname;
END;
The error is relation "$1" doesn't exist, because I'm not binding it correctly.
$function$after theEND; 2) The '$$ .. $$' around the query is not needed. 3) The'$1'should be just$1. See plpgsql structure and [Return query](43.6.1.2. RETURN NEXT and RETURN QUERY) 43.6.1.2. RETURN NEXT and RETURN QUERY.