Repository navigation
Use built-in array types when fetch_types is false - fixes #1164 - #1247
Open
WolfieLeader wants to merge 1 commit into
Open
WolfieLeader wants to merge 1 commit into
WolfieLeader wants to merge 1 commit into
Conversation
Array parsers and serializers were only registered by fetchArrayTypes(), so with fetch_types: false a text[] column came back as the string '{x,y}' and sql.array(['a', 'b']) was sent as 'a,b'. Built-in array OIDs are fixed in the PostgreSQL catalog, so parseOptions now registers them when fetch_types is false. It runs in parseOptions rather than per connection because the listen and subscribe clients reuse the parent's options object and would otherwise register serializers bound to their own transform.
WolfieLeader
marked this pull request as ready for review
October 6, 2026 14:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1164.
With
fetch_types: false, built-in arrays are neither parsed nor serialized:Only
fetchArrayTypes()registers array parsers and serializers, and it runs only whenfetch_typesis true. Cloudflare's Hyperdrive guide for Postgres.js turnsfetch_typesoff to save a round trip.This change registers 22 built-in element/array pairs when
fetch_typesis false. Built-in types can be hard-coded because PostgreSQL fixes their OIDs in its catalog (pg_type.dat), so they are the same in every install. Custom types still needfetch_types.fetch_types: trueis unchanged.Changes
addArrayType()moves fromconnection.jstotypes.jsand takesoptionsfirst.parseOptions()registers the pairs.addArrayType()keeps a parser or serializer that is already set (feat: don't override array type if already exists #578), so user types still win.parseOptions(), not per connection. Per connection, the eager subscribe client filled the parent's serializers first and brokeInsert array with undefined transform.fetch_types: false, built-in array columns now come back as JS arrays instead of'{x,y}'strings. Code that parsed those strings itself will see a change.Test
New
Built-in array types without fetch_typesintests/index.js. Before:22P02 malformed array literal: "c,d". After: passes.node tests/index.jsandnpm run test:cjspass in full on Node 24.21.0 and PostgreSQL 15, set up like CI. Deno not run.eslintis clean. The 22 pairs matchpg_typeon PostgreSQL 12, 15 and 18.Questions
inet[],timetz[],point[]), not only the 22 most common?fetch_typesis true, so the first query does not depend on the type fetch (Wrong inferred array types when invokingsql.array()for the first time. #789)?