fix(postgres): return date/timestamp values verbatim instead of host-local Dates - #417
Merged
Merged
Conversation
…local Dates pg-types parses `timestamp without time zone` and `date` with the multi-argument Date constructor, i.e. in the DBHub host's local timezone. The JSON serializer then renders that Date via toISOString(), so a stored `2026-01-01 12:00:00` came back as `2026-01-01T18:00:00.000Z` on a host in America/Chicago, with the host offset baked in, a misleading `Z` suffix, and microseconds truncated. Register string passthrough parsers for date, timestamp, timestamptz and their array types on DBHub's pool via `PoolConfig.types`, scoped to the pool rather than the process-wide `pg.types` registry. Values now render as the text psql would show. Fixes #416 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EL7QBrNvJJvVHaDvmC9MZL
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is scoped to the Postgres pool, matches the stated bug/acceptance criteria, and is covered by both unit and integration regression tests.
Pull request overview
This PR fixes Postgres date/time value rendering so date, timestamp, and timestamptz are returned as the server’s verbatim text (instead of host-local Date objects that get JSON-serialized with shifted/ambiguous UTC timestamps), addressing issue #416.
Changes:
- Adds a Postgres pool-scoped
typesconfiguration that passthrough-parses date/time OIDs (including array OIDs) as strings. - Wires the custom type parsers into the Postgres connector via
PoolConfig.types(avoiding process-widepg.typesmutation). - Adds unit + integration regression tests covering microseconds, arrays, delegation for other OIDs, and no global mutation.
File summaries
| File | Description |
|---|---|
| src/connectors/postgres/type-parsers.ts | Introduces pool-scoped type parsers to return date/timestamp/timestamptz (and arrays) as verbatim text. |
| src/connectors/postgres/index.ts | Applies the custom type parser config to the connector’s pool to avoid host-timezone shifts. |
| src/connectors/tests/postgres.integration.test.ts | Adds integration regression coverage ensuring executeSQL returns the expected verbatim strings. |
| src/connectors/tests/postgres-type-parsers.test.ts | Adds unit tests verifying passthrough behavior, delegation, timezone-independence, and no global mutation. |
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.
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 #416
Problem
timestamp without time zoneanddatevalues from Postgres came back shifted by the DBHub host's UTC offset. pg-types parses these OIDs with the multi-argumentDateconstructor (host-local time), and the JSON serializer then renders theDateviatoISOString(). On a host inAmerica/Chicago, a stored2026-01-01 12:00:00was returned as2026-01-01T18:00:00.000Z: the host offset baked in, a misleadingZsuffix, and microseconds truncated.datewas also affected (rendered as a shifted midnight instant).timestamptzwas unaffected because pg-types takes theDate.UTCbranch for it.Reproduced locally against the installed
pgwithTZ=America/Chicago:2026-01-01 12:00:002026-01-01T18:00:00.000Z2026-01-012026-01-01T06:00:00.000Z2026-01-01 12:00:00.1234562026-01-01T18:00:00.123ZFix
src/connectors/postgres/type-parsers.tsregisters string passthrough parsers fordate,timestamp,timestamptzand their array types.PoolConfig.types, so it is scoped to DBHub's pool and does not mutate the process-widepg.typesregistry.psqlwould show, with microseconds preserved.timestamptzis included so the three date/time types render consistently and the session offset stays visible.time(OID 1083) already came back as a string and is unchanged.Tests
src/connectors/__tests__/postgres-type-parsers.test.ts: unit tests for the parsers, including host-timezone independence, array types, delegation of other OIDs to pg-types, and no global mutation.src/connectors/__tests__/postgres.integration.test.ts: regression assertion against a real Postgres container.Unit suite passes locally; the Postgres integration suite requires Docker and will run in CI.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EL7QBrNvJJvVHaDvmC9MZL
Generated by Claude Code