Skip to content

Commit

Permalink
Add PostgreSQL STRING_AGG function (#4950)
Browse files Browse the repository at this point in the history
  • Loading branch information
anddani authored and hfhbd committed Apr 2, 2024
1 parent 5a9f089 commit 7a9cd2e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7a9cd2e

Please sign in to comment.