Concatenates strings separated by a specified separator. In PostgreSQL, this is STRING_AGG; in MySQL and SQLite, use GROUP_CONCAT; in Oracle, use LISTAGG; and in SQL Server, use STRING_AGG (since 2017). Syntax and features may differ between databases.
Collects string values from multiple rows into a single string, using GROUP_CONCAT (MySQL), STRING_AGG (PostgreSQL/SQL Server), or LISTAGG (Oracle). Useful for building comma-separated lists per group, like tag lists.
Compatibility
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | Native | 8.0 | Implemented through equivalent GROUP_CONCAT function; default separator is comma |
| PostgreSQL | Native | 9.0 | Supports ORDER BY inside aggregation |
| SQL Server | Native | 2017 (v14.x) | Native support; clean syntax |
| Oracle | Native | 11g Release 2 (11.2) | NOTE: Implemented through equivalent LISTAGG function; supports ordering |
| SQLite | Native | 3.44.0 (released Nov 2023) | Alias added for compatibility with other databases; implemented as alias for GROUP_CONCAT |
Details
The PostgreSQL STRING_AGG() function is an aggregate function that concatenates a list of strings and places a separator between them. It does not add the separator at the end of the string.
Standard Syntax
-- PostgreSQL syntax:
STRING_AGG ( expression, separator [order_by_clause] );
Version Support
MySQL: Native since 8.0
PostgreSQL: Native since 9.0
SQL Server: Native since 2017 (v14.x)
Oracle: Native since 11g Release 2 (11.2)
SQLite: Native since 3.44.0 (released Nov 2023)