0
0
PostgreSQLquery~5 mins

to_tsquery for search terms in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the to_tsquery function do in PostgreSQL?

to_tsquery converts a text search query string into a format that PostgreSQL can use to perform full-text searches.

Click to reveal answer
beginner
How do you combine multiple search terms using to_tsquery?

You use the & operator to combine terms with AND, and the | operator to combine terms with OR inside the to_tsquery string.

Click to reveal answer
intermediate
What is the difference between to_tsquery and plainto_tsquery?

to_tsquery expects a query with operators like & or |, while plainto_tsquery treats the input as plain text and automatically combines terms with AND.

Click to reveal answer
beginner
Write a to_tsquery expression to search for documents containing both 'cat' and 'dog'.

to_tsquery('cat & dog')

Click to reveal answer
intermediate
What happens if you use to_tsquery with an empty string?

It returns an empty query that matches nothing, so no rows will be found in a search.

Click to reveal answer
Which operator in to_tsquery means AND?
A:
B&
C!
D|
What does to_tsquery('cat | dog') search for?
ADocuments containing either 'cat' or 'dog'
BDocuments containing neither 'cat' nor 'dog'
CDocuments containing both 'cat' and 'dog'
DDocuments containing the phrase 'cat dog'
Which function automatically treats input as plain text and combines terms with AND?
Ato_tsquery
Bts_rank
Ctsvector
Dplainto_tsquery
How would you write a to_tsquery to search for 'apple' but not 'banana'?
Ato_tsquery('apple ! banana')
Bto_tsquery('apple | banana')
Cto_tsquery('apple & !banana')
Dto_tsquery('apple & banana')
What type of data does to_tsquery return?
Atsquery type
BText string
CInteger
DBoolean
Explain how to use to_tsquery to search for multiple terms with AND and OR operators.
Think about how you combine words inside the query string.
You got /4 concepts.
    Describe the difference between to_tsquery and plainto_tsquery and when to use each.
    One expects operators, the other treats input as simple words.
    You got /3 concepts.