PostgreSQL Interview Question: what is string_agg() and when do you use it?

Data Cat
3 min readJan 21, 2024
Title — string_agg()

Hi everyone, this post is about the Postgres useful function. Postgres offers a variety of useful functions thanks to committers and I am always grateful for such great community. I wanted to share one useful function, string_agg(), that I recently found. If you are a product manager or analysts who want to aggregate and analyze dataset, this entry is helpful.

“Disclaimer: The views and opinions expressed in this blog post are solely my own and do not reflect those of any entity with which I have been, am now, or will be affiliated. This content was written during a period in which the author was not affiliated with nor belong to any organization that could influence their perspectives. As such, these are author’s personal insights, shared without any external bias or influence.”

Problem Setting

Suppose your company are selling some products. Each row of this table contains the product name and the date it was sold in a market. You want to analyze product trends by season and day in a week.

Table Activities:

+-------------+---------+
| Column Name | Type |
+-------------+---------+
| sell_date | date |
| product | varchar |
+-------------+---------+

--

--