0
0
PostgreSQLquery~10 mins

OUT parameters 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 declare an OUT parameter in a PostgreSQL function.

PostgreSQL
CREATE FUNCTION get_sum(a integer, b integer, [1] integer) AS $$ BEGIN result := a + b; END; $$ LANGUAGE plpgsql;
Drag options to blanks, or click blank then click option'
AOUT result
BIN result
CRETURN result
DVAR result
Attempts:
3 left
💡 Hint
Common Mistakes
Using IN instead of OUT for output parameters.
Trying to use RETURN keyword in parameter declaration.
2fill in blank
medium

Complete the code to assign a value to the OUT parameter inside the function body.

PostgreSQL
CREATE FUNCTION get_product(a integer, b integer, OUT product integer) AS $$ BEGIN [1] := a * b; END; $$ LANGUAGE plpgsql;
Drag options to blanks, or click blank then click option'
Aproduct
BRETURN
Cresult
Doutput
Attempts:
3 left
💡 Hint
Common Mistakes
Using RETURN to assign value instead of the OUT parameter name.
Using a different variable name not declared as OUT.
3fill in blank
hard

Fix the error in the function declaration to correctly use OUT parameters.

PostgreSQL
CREATE FUNCTION get_difference(a integer, b integer, [1] integer) AS $$ BEGIN diff := a - b; END; $$ LANGUAGE plpgsql;
Drag options to blanks, or click blank then click option'
AVAR diff
BIN diff
COUT diff
DRETURN diff
Attempts:
3 left
💡 Hint
Common Mistakes
Using IN instead of OUT for output parameters.
Declaring OUT parameter but still specifying RETURNS integer.
4fill in blank
hard

Fill both blanks to declare two OUT parameters and assign values inside the function.

PostgreSQL
CREATE FUNCTION get_stats(a integer, b integer, [1] integer, [2] integer) AS $$ BEGIN sum := a + b; product := a * b; END; $$ LANGUAGE plpgsql;
Drag options to blanks, or click blank then click option'
AOUT sum
BIN total
COUT product
DVAR result
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing IN and OUT keywords for output parameters.
Not assigning values to both OUT parameters.
5fill in blank
hard

Fill all three blanks to declare OUT parameters and assign values for sum, difference, and product.

PostgreSQL
CREATE FUNCTION calculate(a integer, b integer, [1] integer, [2] integer, [3] integer) AS $$ BEGIN sum := a + b; diff := a - b; product := a * b; END; $$ LANGUAGE plpgsql;
Drag options to blanks, or click blank then click option'
AOUT sum
BOUT diff
COUT product
DIN result
Attempts:
3 left
💡 Hint
Common Mistakes
Using IN instead of OUT for output parameters.
Forgetting to assign values to all OUT parameters.