0
0
PostgreSQLquery~10 mins

String length and position functions 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 get the length of the string 'hello'.

PostgreSQL
SELECT [1]('hello');
Drag options to blanks, or click blank then click option'
Alength
Bposition
Csubstr
Dchar_length
Attempts:
3 left
💡 Hint
Common Mistakes
Using position instead of length.
Using substr which extracts part of a string.
2fill in blank
medium

Complete the code to find the position of 'a' in the string 'banana'.

PostgreSQL
SELECT [1]('a' IN 'banana');
Drag options to blanks, or click blank then click option'
Astrpos
Blength
Cposition
Dchar_length
Attempts:
3 left
💡 Hint
Common Mistakes
Using length instead of position.
Using strpos which is similar but different syntax.
3fill in blank
hard

Fix the error in the code to correctly find the position of 'na' in 'banana'.

PostgreSQL
SELECT position([1] IN 'banana');
Drag options to blanks, or click blank then click option'
A'banana'
B'na'
C"na"
Dna
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the substring.
Using double quotes which are for identifiers.
4fill in blank
hard

Fill both blanks to get the length of 'apple' and find the position of 'p' in it.

PostgreSQL
SELECT [1]('apple') AS len, [2]('p' IN 'apple') AS pos;
Drag options to blanks, or click blank then click option'
Alength
Bposition
Cchar_length
Dstrpos
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up length and char_length.
Using strpos instead of position.
5fill in blank
hard

Fill all three blanks to create a query that returns a dictionary with the uppercase word as key, its length as value, and only include words where length is greater than 3.

PostgreSQL
SELECT jsonb_object_agg([1], [2]) FROM (SELECT UPPER(word) AS [1], [2] FROM words WHERE [3]) sub;
Drag options to blanks, or click blank then click option'
Aword
Blength(word)
Clength(word) > 3
DUPPER(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of UPPER(word) for keys.
Not filtering words by length.
Using wrong syntax for filtering.