Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to safely format a string with a variable using the format function.
PostgreSQL
SELECT format('Hello, %s!', [1]) AS greeting;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the placeholder '%s' as the argument instead of the actual string.
Not using quotes around the string value.
✗ Incorrect
The format function replaces %s with the first argument after the format string, so 'World' is the correct value to insert.
2fill in blank
mediumComplete the code to safely format an integer into a string using the format function.
PostgreSQL
SELECT format('You have %[1] new messages.', 5) AS message;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %s instead of %d for integers.
Using %f which is for floating-point numbers.
✗ Incorrect
The %d placeholder is used for integers in the format function.
3fill in blank
hardFix the error in the code to correctly format a floating-point number with two decimal places.
PostgreSQL
SELECT format('Price: %.2[1]', 12.3456) AS formatted_price;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d or %i which are for integers.
Using %s which is for strings.
✗ Incorrect
The %f placeholder formats floating-point numbers, and .2 specifies two decimal places.
4fill in blank
hardFill both blanks to safely format a string and an integer using the format function.
PostgreSQL
SELECT format('User: %[1], Age: %[2]', 'Alice', 30) AS info;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up %s and %d placeholders.
Using %f for integers.
✗ Incorrect
Use %s for strings and %d for integers in the format function.
5fill in blank
hardFill all three blanks to format a string, an integer, and a floating-point number with one decimal place.
PostgreSQL
SELECT format('Name: %[1], Count: %[2], Score: %.1[3]', 'Bob', 7, 9.876) AS result;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d for floats or %f for integers.
Omitting the decimal precision for floats.
✗ Incorrect
Use %s for strings, %d for integers, and %f for floating-point numbers with decimal precision.