Bird
0
0

Which of the following is the correct syntax to use ts_headline to highlight the word 'apple' in the text column 'description' with the 'english' configuration?

easy📝 Syntax Q12 of 15
PostgreSQL - Full-Text Search
Which of the following is the correct syntax to use ts_headline to highlight the word 'apple' in the text column 'description' with the 'english' configuration?
ASELECT ts_headline(description, 'apple', 'english') FROM products;
BSELECT ts_headline('apple', description) FROM products;
CSELECT ts_headline(description, to_tsquery('apple')) FROM products;
DSELECT ts_headline(description, 'apple') FROM products;
Step-by-Step Solution
Solution:
  1. Step 1: Recall ts_headline syntax

    The function syntax is ts_headline(text, query [, config]), where query is a tsquery type or text query string, and config is optional language.
  2. Step 2: Analyze options

    SELECT ts_headline(description, 'apple', 'english') FROM products; uses text, query string, and language config correctly. SELECT ts_headline(description, 'apple') FROM products; misses language but is valid; however, for 'english' configuration, it requires the config. SELECT ts_headline('apple', description) FROM products; has arguments reversed. SELECT ts_headline(description, to_tsquery('apple')) FROM products; uses to_tsquery but misses language config.
  3. Final Answer:

    SELECT ts_headline(description, 'apple', 'english') FROM products; -> Option A
  4. Quick Check:

    Correct syntax with language = A [OK]
Quick Trick: Use ts_headline(text, query, 'language') for best results [OK]
Common Mistakes:
  • Swapping text and query arguments
  • Omitting language config when needed
  • Passing plain text instead of tsquery or query string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes