Skip to content

fix: serialize extension arrays after provisioning - #4

Merged
jgpruitt merged 1 commit into
mainfrom
fix/postgresjs-extension-arrays
Sep 4, 2026
Merged

fix: serialize extension arrays after provisioning#4
jgpruitt merged 1 commit into
mainfrom
fix/postgresjs-extension-arrays

Conversation

@jgpruitt

@jgpruitt jgpruitt commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • bind batch_upsert parallel arrays with postgres.js's built-in text[] serializer
  • cast the parameterized arrays to uuid[], public.ltree[], tstzrange[], and the configured pgvector array type in SQL
  • avoid stale custom-array serializer maps when createIndex() installs extensions after a pool connection starts
  • add a fresh-template0, single-connection regression covering prepared statement reuse, temporal values, nulls, escaping, halfvec, and vector
  • document the fix in the changelog

Root cause

postgres.js discovers custom array serializers when a connection starts. When createIndex() installs ltree and pgvector on that already-open connection, its type map remains stale. Bare JavaScript arrays then fall back to comma-separated string conversion for the newly resolved custom array OID and PostgreSQL rejects the value with 22P02.

prepare: false does not fix this on a genuinely fresh database; reconnecting after extension installation only appeared to do so.

Validation

  • ./bun run check
  • core database integration suite: 56/56 passed
  • fresh-extension regression against PostgreSQL 18
  • packed npm artifact reproduction with default postgres.js settings on a fresh database

@jgpruitt jgpruitt self-assigned this Sep 4, 2026
@jgpruitt jgpruitt added the bug Something isn't working label Sep 4, 2026
@jgpruitt
jgpruitt requested a lite review from Copilot September 4, 2026 14:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, aligns with the batch_upsert routine’s parameter types, and is validated by a deterministic regression test covering the reported failure mode.

Pull request overview

This PR fixes a postgres.js type-discovery edge case where extension-installed array types (e.g., ltree[], vector[]/halfvec[]) aren’t recognized on an already-open connection, causing batch array parameters to serialize incorrectly. The solution forces batch arrays through postgres.js’s built-in text[] serializer and lets PostgreSQL cast to the routine’s target array types, plus adds a regression test to prove correctness on a single-connection pool with prepared statement reuse.

Changes:

  • Bind batch_upsert parallel arrays via sql.array(..., textOID) and cast to uuid[], public.ltree[], tstzrange[], and public.vector[]/public.halfvec[] in SQL.
  • Add a fresh-template0 regression test that deterministically reproduces the extension-installation-on-same-connection scenario and verifies escaping/null/temporal/vector behavior.
  • Document the fix in the changelog.
File summaries
File Description
packages/core/test/support/db.ts Adds optional max pool size support to force a single-connection pool for deterministic regression coverage.
packages/core/test/fresh-extension-arrays.integration.test.ts New integration regression ensuring extension array types serialize correctly even when installed after connection startup.
packages/core/src/write.ts Uses sql.array with text[] + explicit casts to avoid stale per-connection custom array serializer maps.
CHANGELOG.md Documents the fixed behavior for upsert/upsertMany on the same pool connection used by createIndex.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jgpruitt
jgpruitt merged commit b6ea95e into main Sep 4, 2026
11 checks passed
@jgpruitt
jgpruitt deleted the fix/postgresjs-extension-arrays branch September 4, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants