Bird
0
0

Which of the following is the correct syntax to aggregate the column city with ', ' separator using STRING_AGG?

easy📝 Syntax Q3 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Which of the following is the correct syntax to aggregate the column city with ', ' separator using STRING_AGG?
ASELECT STRING_AGG(city, ',') FROM locations;
BSELECT STRING_AGG(city) FROM locations;
CSELECT STRING_AGG(city, ', ') FROM locations;
DSELECT STRING_AGG(city, city) FROM locations;
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for STRING_AGG

    STRING_AGG requires two arguments: the column and the separator string.
  2. Step 2: Evaluate each option

    SELECT STRING_AGG(city, ',') FROM locations; uses ',' (comma only, no space). SELECT STRING_AGG(city) FROM locations; misses separator argument. SELECT STRING_AGG(city, ', ') FROM locations; uses the correct ', ' separator. SELECT STRING_AGG(city, city) FROM locations; uses column as separator, which is invalid.
  3. Final Answer:

    SELECT STRING_AGG(city, ', ') FROM locations; -> Option C
  4. Quick Check:

    Correct syntax = column + separator string [OK]
Quick Trick: STRING_AGG needs column and separator string [OK]
Common Mistakes:
  • Omitting the separator argument
  • Using column name as separator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes