I have an SQL function which has a DO block, and when trying to access an argument of the enclosing function inside the DO block I get a " column does not exist" error. What am I missing?
CREATE OR REPLACE FUNCTION f1(a1 TEXT) RETURNS VOID AS $$
DO $DO$
BEGIN
RAISE NOTICE 'a1 = %', a1;
END
$DO$;
$$ LANGUAGE SQL VOLATILE;
SELECT f1('AA');
ERROR: column "a1" does not exist SQL state: 42703 Context: PL/pgSQL function inline_code_block line 3 at RAISE SQL function "f1" statement 1
begin ...end, put areturn queryin front of theselectand changelanguage sqlto languageplpgsql. You apparently need PL/pgSQL otherwise you wouldn't have theDOblock.