Bird
0
0

Consider the table orders with rows:

medium📝 query result Q5 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Consider the table orders with rows:
(101, 'Pen'), (102, 'Pencil'), (103, 'Eraser')
What is the result of:
SELECT STRING_AGG(product, '|') FROM orders;?
A"Pen, Pencil, Eraser"
B"Pen|Pencil|Eraser"
C"PenPencilEraser"
D"Pen| Pencil| Eraser"
Step-by-Step Solution
Solution:
  1. Step 1: Identify separator used

    The separator is '|', so strings will be joined with this character without spaces.
  2. Step 2: Join product names with separator

    Result is "Pen|Pencil|Eraser" exactly as "Pen|Pencil|Eraser".
  3. Final Answer:

    "Pen|Pencil|Eraser" -> Option B
  4. Quick Check:

    Separator '|' joins strings exactly [OK]
Quick Trick: Separator is literal string between quotes [OK]
Common Mistakes:
  • Adding spaces not in separator
  • Confusing separator with comma

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes