0
0
PostgreSQLquery~10 mins

Format function for safe formatting 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 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'
A'Hello'
B'World'
C'%s'
D'greeting'
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.
2fill in blank
medium

Complete 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'
Af
Bs
Cd
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using %s instead of %d for integers.
Using %f which is for floating-point numbers.
3fill in blank
hard

Fix 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'
Ad
Bi
Cs
Df
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d or %i which are for integers.
Using %s which is for strings.
4fill in blank
hard

Fill 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'
As
Bd
Cf
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up %s and %d placeholders.
Using %f for integers.
5fill in blank
hard

Fill 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'
As
Bd
Cf
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d for floats or %f for integers.
Omitting the decimal precision for floats.