diff --git a/dialects/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/PostgreSqlTypeResolver.kt b/dialects/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/PostgreSqlTypeResolver.kt index b4da5d60e36..fd2b09f3a0a 100644 --- a/dialects/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/PostgreSqlTypeResolver.kt +++ b/dialects/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/PostgreSqlTypeResolver.kt @@ -167,6 +167,7 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes "json_typeof", "jsonb_typeof", "json_agg", "jsonb_agg", "json_object_agg", "jsonb_object_agg", -> IntermediateType(TEXT) + "string_agg" -> IntermediateType(TEXT) "json_array_length", "jsonb_array_length" -> IntermediateType(INTEGER) "jsonb_path_exists", "jsonb_path_match", "jsonb_path_exists_tz", "jsonb_path_match_tz" -> IntermediateType(BOOLEAN) "currval", "lastval", "nextval", "setval" -> IntermediateType(BIG_INT) diff --git a/sqldelight-gradle-plugin/src/test/integration-postgresql/src/main/sqldelight/app/cash/sqldelight/postgresql/integration/Dog.sq b/sqldelight-gradle-plugin/src/test/integration-postgresql/src/main/sqldelight/app/cash/sqldelight/postgresql/integration/Dog.sq index a123037290f..a94e0628c42 100644 --- a/sqldelight-gradle-plugin/src/test/integration-postgresql/src/main/sqldelight/app/cash/sqldelight/postgresql/integration/Dog.sq +++ b/sqldelight-gradle-plugin/src/test/integration-postgresql/src/main/sqldelight/app/cash/sqldelight/postgresql/integration/Dog.sq @@ -64,3 +64,10 @@ deleteAndReturnAll: DELETE FROM dog WHERE name = ? RETURNING *; + +selectDogsStringAggName: +SELECT breed, + STRING_AGG(name, ',') +FROM dog +GROUP BY breed +ORDER BY breed; diff --git a/sqldelight-gradle-plugin/src/test/integration-postgresql/src/test/kotlin/app/cash/sqldelight/postgresql/integration/PostgreSqlTest.kt b/sqldelight-gradle-plugin/src/test/integration-postgresql/src/test/kotlin/app/cash/sqldelight/postgresql/integration/PostgreSqlTest.kt index 595c2de0b7a..a62686a1128 100644 --- a/sqldelight-gradle-plugin/src/test/integration-postgresql/src/test/kotlin/app/cash/sqldelight/postgresql/integration/PostgreSqlTest.kt +++ b/sqldelight-gradle-plugin/src/test/integration-postgresql/src/test/kotlin/app/cash/sqldelight/postgresql/integration/PostgreSqlTest.kt @@ -273,6 +273,19 @@ class PostgreSqlTest { } } + @Test fun testStringAgg() { + database.dogQueries.insertDog("Tilda", "Pomeranian") + database.dogQueries.insertDog("Bruno", "Pomeranian") + database.dogQueries.insertDog("Mads", "Broholmer") + + database.dogQueries.selectDogsStringAggName().executeAsList().let { + assertThat(it).containsExactly( + SelectDogsStringAggName("Broholmer", "Mads"), + SelectDogsStringAggName("Pomeranian", "Tilda,Bruno"), + ) + } + } + @Test fun testSerial() { database.run { oneEntityQueries.transaction {