Skip to content

feat(postgrest): add casts, JSON paths and aggregates as column expressions - #2114

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2988-casts-json-paths-aggregates
Nov 17, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2988-casts-json-paths-aggregates

Conversation

@spydon

@spydon spydon commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Step 5 of SDK-2765, port of supabase-flutter #1797 and #1798. Closes SDK-2988.

  • json_text(), json_text_at(), json_object(), json_object_at() on JSON columns return a JsonPath, which filters, orders and has is_null(). Operands of a -> path are sent as JSON.
  • cast(sql_type, value_type), sum(), avg(), min(), max(), count() and DerivedExpression.count_all() return a select-only DerivedExpression, so filtering or ordering on one is a type error. A cast of a cast and an aggregate of an aggregate raise ValueError.
  • select_only() takes any Expression. JSON paths and derived expressions are aliased to their own expression (shortened past 63 bytes like Dart) and PartialRow reads them by response_key. min()/max() decode as the column, sum() without its Field constraints, avg() as Decimal over Decimal.
  • The select list cleaner no longer strips whitespace after an escaped quote inside a quoted alias.
  • Test stack enables db_aggregates_enabled. Integration tests cover each new expression.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added typed JSON-path access for object keys and array elements, including selection, filtering, and ordering.
    • Added cast and aggregate expressions, including sum, average, minimum, maximum, count, and count-all.
    • Selected derived values now support typed result decoding and stable response keys, including for long expressions.
    • Database aggregate queries are now enabled.
  • Bug Fixes
    • Improved handling of escaped quotes in selected column names.

The change adds typed JSON-path, cast, and aggregate expressions. Query selection now accepts general expressions, and selected results are looked up by response key. JSON-path filters serialize JSON operands, while casts and aggregates have typed result handling. The change also enables PostgREST aggregates for the authenticator role and adds unit, integration, and type-check coverage.

Sequence Diagram(s)

sequenceDiagram
  participant TypedQueryBuilder
  participant TableExecutor
  participant PostgREST
  participant PartialRow
  TypedQueryBuilder->>TableExecutor: Pass selected expressions
  TableExecutor->>PostgREST: Send select list using expression aliases
  PostgREST-->>PartialRow: Return selected values keyed by response key
  PartialRow-->>TypedQueryBuilder: Decode expression values
Loading

Possibly related PRs

Change: Feature

Merge Risk: Minimal · up to 03cf5

This adds typed JSON-path, cast, and aggregate expressions to the PostgREST client, with tests covering rendering, selection, and decoding. No concrete merge-blocking risk was identified.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0eecc0b3-f4ae-4498-940e-920970d5b797
Commits

Reviewing files that changed from the base of the PR and between ca79c71 and 03cf562.

Files selected for processing: 2

  • sdk-compliance.yaml
  • src/postgrest/src/postgrest/table_executor.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@spydon
spydon force-pushed the lukasklingsbo/sdk-2988-casts-json-paths-aggregates branch from ca79c71 to 03cf562 Compare November 17, 2026 15:10
@spydon
spydon merged commit b3d4810 into main Nov 17, 2026
26 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2988-casts-json-paths-aggregates branch November 17, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant