Skip to content

[BUG]: pg timestamp: a Date past the year 9999 is sent as "+010000-…", which PostgreSQL refuses (22009) #6552

Open

Description

@rinarakaki

What version of drizzle-orm are you using?

1.0.0-rc.4

What version of drizzle-kit are you using?

1.0.0-rc.4 (not involved)

Other packages

pg 8.23.1, PostgreSQL 18

Describe the Bug

A pg timestamp column sends a Date as value.toISOString() (PgTimestamp.mapToDriverValue, and PgTimestampString's, in pg-core/columns/timestamp.js). For a year past 9999, toISOString writes the expanded-year form, and PostgreSQL refuses that:

ERROR:  time zone displacement out of range: "+010000-01-01T00:00:00.000Z"   (SQLSTATE 22009)

PostgreSQL itself takes the year. select '10000-01-01T00:00:00.000Z'::timestamptz works, and its timestamps run to 294276 AD. Only the +010000- spelling is refused.

Repro:

const t = pgTable("t", { at: timestamp({ withTimezone: true }) });
await db.insert(t).values({ at: new Date(Date.UTC(10000, 0, 1)) });
// DrizzleQueryError, cause: time zone displacement out of range (22009)

Expected: the row is written. For example, a year of 10000 or later could be sent without the sign and the zero padding, as 10000-01-01T00:00:00.000Z.

Where it bites: a time the application doesn't set itself. An API can take a date given in milliseconds where seconds were meant. Stripe takes a subscription's cancel_at of 1,800,000,000,000 s, which is the year 59009. Then every write of that row fails. We bound such times at 9999-12-31T23:59:59Z in the meantime.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions