Skip to content

fix(postgres): return date/timestamp values verbatim instead of host-local Dates - #417

Merged
tianzhou merged 1 commit into
mainfrom
claude/verdict-issue-416-3z9sv1
Sep 2, 2026
Merged

fix(postgres): return date/timestamp values verbatim instead of host-local Dates#417
tianzhou merged 1 commit into
mainfrom
claude/verdict-issue-416-3z9sv1

Conversation

@tianzhou

@tianzhou tianzhou commented Sep 2, 2026

Copy link
Copy Markdown
Member

Fixes #416

Problem

timestamp without time zone and date values from Postgres came back shifted by the DBHub host's UTC offset. pg-types parses these OIDs with the multi-argument Date constructor (host-local time), and the JSON serializer then renders the Date via toISOString(). On a host in America/Chicago, a stored 2026-01-01 12:00:00 was returned as 2026-01-01T18:00:00.000Z: the host offset baked in, a misleading Z suffix, and microseconds truncated. date was also affected (rendered as a shifted midnight instant). timestamptz was unaffected because pg-types takes the Date.UTC branch for it.

Reproduced locally against the installed pg with TZ=America/Chicago:

OID Type Input Before
1114 timestamp 2026-01-01 12:00:00 2026-01-01T18:00:00.000Z
1082 date 2026-01-01 2026-01-01T06:00:00.000Z
1114 timestamp 2026-01-01 12:00:00.123456 2026-01-01T18:00:00.123Z

Fix

  • New src/connectors/postgres/type-parsers.ts registers string passthrough parsers for date, timestamp, timestamptz and their array types.
  • Wired in via PoolConfig.types, so it is scoped to DBHub's pool and does not mutate the process-wide pg.types registry.
  • Values now render as the text psql would show, with microseconds preserved. timestamptz is included so the three date/time types render consistently and the session offset stays visible.
  • Plain 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

…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
Copilot AI lite review requested due to automatic review settings September 2, 2026 02:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 types configuration 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-wide pg.types mutation).
  • 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.

@tianzhou
tianzhou merged commit 43e33c5 into main Sep 2, 2026
3 checks passed
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.

Postgres: timestamp-without-time-zone values are shifted by the server host's local timezone

3 participants