Complete the code to get the length of the string 'hello'.
SELECT [1]('hello');
The length function returns the number of characters in a string in PostgreSQL.
Complete the code to find the position of 'a' in the string 'banana'.
SELECT [1]('a' IN 'banana');
The position function returns the location of a substring inside a string in PostgreSQL.
Fix the error in the code to correctly find the position of 'na' in 'banana'.
SELECT position([1] IN 'banana');
The substring must be a string literal enclosed in single quotes in PostgreSQL.
Fill both blanks to get the length of 'apple' and find the position of 'p' in it.
SELECT [1]('apple') AS len, [2]('p' IN 'apple') AS pos;
length returns the string length, and position finds the substring position.
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.
SELECT jsonb_object_agg([1], [2]) FROM (SELECT UPPER(word) AS [1], [2] FROM words WHERE [3]) sub;
We use UPPER(word) as the key, length(word) as the value, and filter with length(word) > 3.