Recall & Review
beginner
What does the ARRAY_AGG function do in PostgreSQL?
ARRAY_AGG collects values from multiple rows into a single array.
Click to reveal answer
beginner
How do you use ARRAY_AGG to get all employee names in one array from a table named employees?
Use: SELECT ARRAY_AGG(name) FROM employees;
Click to reveal answer
intermediate
Can ARRAY_AGG be combined with GROUP BY? If yes, why?
Yes, to collect values into arrays grouped by a column, like departments.
Click to reveal answer
intermediate
What happens if you use ARRAY_AGG on a column with NULL values?
NULL values are included in the resulting array unless filtered out.
Click to reveal answer
advanced
How can you order elements inside the array created by ARRAY_AGG?
Use ORDER BY inside ARRAY_AGG, like ARRAY_AGG(name ORDER BY name ASC).
Click to reveal answer
What is the main purpose of ARRAY_AGG in PostgreSQL?
✗ Incorrect
ARRAY_AGG collects values from multiple rows into a single array.
Which SQL clause is commonly used with ARRAY_AGG to group results?
✗ Incorrect
GROUP BY groups rows so ARRAY_AGG can collect values per group.
How do you exclude NULL values from the array created by ARRAY_AGG?
✗ Incorrect
Filtering NULLs before aggregation excludes them from the array.
How can you sort the elements inside the array returned by ARRAY_AGG?
✗ Incorrect
You can specify ORDER BY inside ARRAY_AGG to sort elements.
What type of data does ARRAY_AGG return?
✗ Incorrect
ARRAY_AGG returns an array containing aggregated values.
Explain how ARRAY_AGG works and give an example query using it.
Think about gathering many values into one list.
You got /3 concepts.
Describe how to handle NULL values and ordering when using ARRAY_AGG.
Consider filtering and sorting inside the aggregation.
You got /3 concepts.