Complete the code to iterate over each element in the array using FOREACH.
DECLARE my_array integer[] := ARRAY[1, 2, 3]; element integer; BEGIN FOREACH element [1] ARRAY my_array LOOP RAISE NOTICE '%', element; END LOOP; END;
The correct syntax to iterate over an array in PostgreSQL using FOREACH is FOREACH element IN ARRAY my_array.
Complete the code to declare an array of text values.
DECLARE
fruits text[] := [1];
BEGIN
NULL;
END;In PostgreSQL, arrays are declared using the ARRAY[...] syntax.
Fix the error in the FOREACH loop to correctly iterate over the array.
DECLARE nums integer[] := ARRAY[10, 20, 30]; n integer; BEGIN FOREACH n [1] nums LOOP RAISE NOTICE '%', n; END LOOP; END;
The FOREACH loop requires the keyword IN ARRAY before the array variable to iterate correctly.
Fill both blanks to create a FOREACH loop that iterates over a text array and prints each fruit.
DECLARE fruits text[] := ARRAY['apple', 'banana', 'cherry']; fruit text; BEGIN FOREACH fruit [1] [2] fruits LOOP RAISE NOTICE '%', fruit; END LOOP; END;
The correct syntax is FOREACH fruit IN ARRAY fruits to iterate over the array.
Fill all three blanks to declare an integer array, iterate over it with FOREACH, and print each number.
DECLARE numbers [1] := [2]; num integer; BEGIN FOREACH num [3] numbers LOOP RAISE NOTICE '%', num; END LOOP; END;
We declare numbers as an integer array with integer[], assign it using ARRAY[5, 10, 15], and iterate using FOREACH num IN ARRAY numbers.