Skip to content

PRS-215: Emit jsonb_build_object with 50-pair chunking in Postgres adapter#999

Open
prisma-gremlin[bot] wants to merge 1 commit into
mainfrom
PRS-215-postgres-jsonb-build-object-chunking
Open

PRS-215: Emit jsonb_build_object with 50-pair chunking in Postgres adapter#999
prisma-gremlin[bot] wants to merge 1 commit into
mainfrom
PRS-215-postgres-jsonb-build-object-chunking

Conversation

@prisma-gremlin

@prisma-gremlin prisma-gremlin Bot commented Jul 16, 2026

Copy link
Copy Markdown

Requested by Alexey Orlenko · Slack thread

What & why

The Postgres adapter's renderJsonObjectExpr previously emitted a single json_build_object(...) call with all key/value pairs inline. PostgreSQL caps function-call arguments at 100, so an object with more than 50 key/value pairs (100 args) would error at runtime. This switches the render path to jsonb_build_object and batches entries 50 key/value pairs per call, merging the per-chunk objects with the JSONB || concatenation operator. JSONB is required because || concatenation is only defined on jsonb, not plain json.

For 50 or fewer pairs, a single jsonb_build_object(...) call is emitted with no || — same shape as before, just jsonb instead of json.

Changes

  • packages/3-targets/6-adapters/postgres/src/core/sql-renderer.tsrenderJsonObjectExpr now renders jsonb_build_object, chunking entries into batches of 50 pairs and joining batches with ||.
  • packages/3-targets/6-adapters/postgres/README.md — prose updated from json_build_object to jsonb_build_object, plus a note describing the chunking behavior and the 100-argument cap rationale.
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts — fixed an existing assertion that still expected json_build_object; added two tests covering the ≤50-field case (single call, no ||) and the >50-field case (multiple calls merged with ||, each holding ≤50 key/value pairs).
  • packages/3-extensions/pgvector/test/rich-adapter.test.ts — fixed the rich-adapter assertion that still expected json_build_object.
  • docs/architecture docs/subsystems/3. Query Lanes.md — render-path doc updated to reflect jsonb_build_object and the chunking behavior (doc-maintenance rule).

Prior art & tracking

Mirrors the approach from prisma-engines#4555. Tracks Linear issue PRS-215.

Created by Mohawk

Summary by CodeRabbit

  • New Features

    • PostgreSQL JSON aggregation now uses JSONB for improved compatibility and merging support.
    • Large JSON objects are automatically split into manageable chunks and combined safely.
    • Empty JSON objects are rendered correctly using PostgreSQL JSONB syntax.
  • Documentation

    • Updated SQL DSL and PostgreSQL adapter documentation with the new JSONB aggregation behavior and large-object handling details.

…apter

renderJsonObjectExpr now emits jsonb_build_object instead of json_build_object, batching entries at 50 key/value pairs per call (100 args, Postgres' function-call argument cap) and merging per-chunk objects with the JSONB || concatenation operator. Objects of 50 or fewer pairs render a single call with no concatenation.

Updates the adapter README prose and the Query Lanes subsystem doc, fixes the pgvector rich-adapter assertion that still expected json_build_object, and adds adapter tests covering the <=50 and >50-field chunking cases.

Refs: PRS-215, prisma-engines#4555
Signed-off-by: Gremlin <gremlin[bot]@users.noreply.github.com>
@prisma-gremlin
prisma-gremlin Bot requested a review from a team as a code owner July 16, 2026 17:25
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: bfc59a66-67f4-4e5a-b634-32a31e074b8a

📥 Commits

Reviewing files that changed from the base of the PR and between 98cf9c0 and ac99826.

📒 Files selected for processing (5)
  • docs/architecture docs/subsystems/3. Query Lanes.md
  • packages/3-extensions/pgvector/test/rich-adapter.test.ts
  • packages/3-targets/6-adapters/postgres/README.md
  • packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts

📝 Walkthrough

Walkthrough

The PostgreSQL SQL renderer now uses jsonb_build_object, splits objects into chunks of up to 50 pairs, and merges chunks with ||. Adapter tests, rich adapter assertions, architecture documentation, and the PostgreSQL README reflect the updated rendering.

Changes

PostgreSQL JSONB rendering

Layer / File(s) Summary
JSONB rendering and coverage
packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts, packages/3-targets/6-adapters/postgres/test/adapter.test.ts
JSON object expressions render with jsonb_build_object, including chunking into groups of up to 50 pairs joined by `
JSONB rendering documentation and integration
packages/3-targets/6-adapters/postgres/README.md, docs/architecture docs/subsystems/3. Query Lanes.md, packages/3-extensions/pgvector/test/rich-adapter.test.ts
Documentation and rich adapter expectations describe and assert JSONB aggregation and wide-object merging behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: wmadden

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: switching to jsonb_build_object with 50-pair chunking in the Postgres adapter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch PRS-215-postgres-jsonb-build-object-chunking

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 159.04 KB (+0.05% 🔺)
postgres / emit 132.57 KB (+0.06% 🔺)
mongo / no-emit 98.71 KB (0%)
mongo / emit 89.43 KB (0%)
cf-worker / no-emit 185.21 KB (+0.04% 🔺)
cf-worker / emit 155.97 KB (+0.05% 🔺)

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@999

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@999

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@999

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@999

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@999

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@999

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@999

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@999

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@999

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@999

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@999

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@999

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@999

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@999

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@999

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@999

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@999

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@999

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@999

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@999

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@999

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@999

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@999

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@999

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@999

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@999

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@999

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@999

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@999

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@999

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@999

@prisma-next/config-loader

npm i https://pkg.pr.new/@prisma-next/config-loader@999

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@999

@prisma-next/language-server

npm i https://pkg.pr.new/@prisma-next/language-server@999

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@999

prisma-next

npm i https://pkg.pr.new/prisma-next@999

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@999

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@999

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@999

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@999

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@999

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@999

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@999

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@999

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@999

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@999

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@999

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@999

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@999

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@999

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@999

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@999

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@999

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@999

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@999

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@999

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@999

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@999

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@999

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@999

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@999

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@999

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@999

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@999

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@999

commit: ac99826

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.

0 participants