0
0
PostgreSQLquery~10 mins

DO blocks for anonymous code in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a DO block in PostgreSQL.

PostgreSQL
DO [1] $$ BEGIN RAISE NOTICE 'Hello, world!'; END; $$;
Drag options to blanks, or click blank then click option'
ALANGUAGE javascript
BLANGUAGE sql
CLANGUAGE python
DLANGUAGE plpgsql
Attempts:
3 left
💡 Hint
Common Mistakes
Using a language not supported by PostgreSQL DO blocks.
Omitting the LANGUAGE keyword.
2fill in blank
medium

Complete the code to declare a variable inside a DO block.

PostgreSQL
DO LANGUAGE plpgsql $$ DECLARE my_var [1]; BEGIN my_var := 10; RAISE NOTICE 'Value: %', my_var; END; $$;
Drag options to blanks, or click blank then click option'
Ainteger
Bdate
Cboolean
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using a text type for a numeric value.
Not declaring the variable type.
3fill in blank
hard

Fix the error in the DO block by completing the missing keyword.

PostgreSQL
DO LANGUAGE plpgsql $$ [1] my_var integer := 5; BEGIN RAISE NOTICE 'Value: %', my_var; END; $$;
Drag options to blanks, or click blank then click option'
ADECLARE
BSET
CDEFINE
DCREATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using SET or CREATE instead of DECLARE.
Placing variable declarations inside BEGIN without DECLARE.
4fill in blank
hard

Fill the blank to complete the DO block that loops from 1 to 3 and raises a notice.

PostgreSQL
DO LANGUAGE plpgsql $$ DECLARE i [1]; BEGIN FOR i IN 1..3 LOOP RAISE NOTICE 'Number: %', i; END LOOP; END; $$;
Drag options to blanks, or click blank then click option'
Atext
Bboolean
Cinteger
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Using text or boolean types for loop counters.
Not declaring the variable before BEGIN.
5fill in blank
hard

Fill all three blanks to complete a DO block that declares a variable, assigns a value, and raises a notice.

PostgreSQL
DO LANGUAGE plpgsql $$ DECLARE my_var [1]; BEGIN my_var := [2]; RAISE NOTICE 'Value is %', [3]; END; $$;
Drag options to blanks, or click blank then click option'
Ainteger
B20
Cmy_var
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a string to an integer variable.
Printing a value instead of the variable.