Skip to content

griffio/sqldelight-postgres-json-aggregates

Repository files navigation

SqlDelight 2.2.x Postgresql Json Aggregate support

https://github.com/cashapp/sqldelight

Version: 2.2.0-SNAPSHOT

Support JSON Aggregate Functions useful for schema-less column data

https://www.postgresql.org/docs/current/functions-aggregate.html

json_object_agg
jsonb_object_agg

PostgreSql 16 functions

json_agg_strict
jsonb_agg_strict

json_object_agg_strict 
jsonb_object_agg_strict

json_object_agg_unique
jsonb_object_agg_unique

json_object_agg_unique_strict
jsonb_object_agg_unique_strict

String is the input and output type for the table API for JSON/JSONB columns

Add Json aggregate FILTER clause

SELECT json_agg(data) FILTER (WHERE (data->>'in_stock')::BOOLEAN) FROM SomeTable;
SELECT jsonb_agg(data->'color') FILTER (WHERE data ?? 'color') AS colors FROM SomeTable;

SELECT jsonb_object_agg(key, value ORDER BY key DESC) FILTER (WHERE key IS NOT NULL) FROM SomeTable;
SELECT jsonb_object_agg_strict(key, value) FROM SomeTable;

createdb topics &&
./gradlew build &&
./gradlew flywayMigrate

Flyway db migrations https://documentation.red-gate.com/fd/gradle-task-184127407.html

About

SqlDelight PostgreSql JSON Aggregate functions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages