Complete the code to start a DO block in PostgreSQL.
DO [1] $$ BEGIN RAISE NOTICE 'Hello, world!'; END; $$;
The DO block in PostgreSQL requires specifying the language, usually plpgsql for procedural code.
Complete the code to declare a variable inside a DO block.
DO LANGUAGE plpgsql $$ DECLARE my_var [1]; BEGIN my_var := 10; RAISE NOTICE 'Value: %', my_var; END; $$;
Variables in PL/pgSQL must have a type. Here, my_var is an integer.
Fix the error in the DO block by completing the missing keyword.
DO LANGUAGE plpgsql $$ [1] my_var integer := 5; BEGIN RAISE NOTICE 'Value: %', my_var; END; $$;
In PL/pgSQL DO blocks, variables must be declared in a DECLARE section before the BEGIN block.
Fill the blank to complete the DO block that loops from 1 to 3 and raises a notice.
DO LANGUAGE plpgsql $$ DECLARE i [1]; BEGIN FOR i IN 1..3 LOOP RAISE NOTICE 'Number: %', i; END LOOP; END; $$;
The variable i is declared as an integer and used in the FOR loop.
Fill all three blanks to complete a DO block that declares a variable, assigns a value, and raises a notice.
DO LANGUAGE plpgsql $$ DECLARE my_var [1]; BEGIN my_var := [2]; RAISE NOTICE 'Value is %', [3]; END; $$;
The variable my_var is declared as integer, assigned 20, and printed.