0
0
PostgreSQLquery~10 mins

to_tsvector for document conversion 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 convert the text 'Hello world' into a tsvector.

PostgreSQL
SELECT to_tsvector([1]);
Drag options to blanks, or click blank then click option'
A'Hello world'
B'simple'
C'english'
D'french'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing only the language configuration without the text.
Not using quotes around the text.
2fill in blank
medium

Complete the code to convert the text 'The quick brown fox' using the English text search configuration.

PostgreSQL
SELECT to_tsvector([1], 'The quick brown fox');
Drag options to blanks, or click blank then click option'
A'simple'
B'spanish'
C'french'
D'english'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a language configuration that does not match the text language.
Omitting the language configuration when needed.
3fill in blank
hard

Fix the error in the code to convert the text 'Cats and dogs' into a tsvector using the simple configuration.

PostgreSQL
SELECT to_tsvector([1] 'Cats and dogs');
Drag options to blanks, or click blank then click option'
A'simple',
B'english',
C'simple'
D'english'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing comma between arguments.
Using quotes incorrectly.
4fill in blank
hard

Fill both blanks to convert the text 'PostgreSQL is great' using the English configuration and alias the result as 'document'.

PostgreSQL
SELECT to_tsvector([1], [2]) AS document;
Drag options to blanks, or click blank then click option'
A'english'
B'PostgreSQL is great'
C'simple'
D'Postgres is great'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments.
Using incorrect text strings.
5fill in blank
hard

Fill all three blanks to create a query that converts the text 'I love databases' using the simple configuration, and filters results where the tsvector contains 'love'.

PostgreSQL
SELECT to_tsvector([1], [2]) AS doc_vector WHERE to_tsvector([1], [2]) @@ to_tsquery([1], [3]);
Drag options to blanks, or click blank then click option'
A'simple'
B'I love databases'
C'love'
D'english'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different configurations for to_tsvector and to_tsquery.
Forgetting to alias the tsvector before using it in WHERE.