What's the reason behind very "tolerant" error checking during stored procedure compilation? Why PostgreSQL allows using variable (j_var) that doesn't exists? It isn't column name or isn't declared anywhere. Like in example below:
CREATE OR REPLACE FUNCTION test() RETURNS int AS $BODY$ BEGIN
select 1 WHERE 1 > j_var; RETURN 2; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100;
PLpgSQL doesn't check a identifiers inside embedded SQL before execution. In this case j_var can be theoretically some SQL identifiers - the possibility or impossibility is not know in function validation stage.
It has some plus and minus points. The plus - there are not strong dependency between database objects and PL code. The minus - lot of bugs are not detected in validation stage. But this issue can be solved by plpgsql_check extension https://github.com/okbob/plpgsql_check/