Skip to content

EXPLAIN ANALYZE fails with date/time field value out of range` when args contain Unix timestamps in milliseconds/microseconds #21

@orinowl

Description

@orinowl

When running EXPLAIN ANALYZE on a query that has a TIMESTAMP WITH TIME ZONE parameter passed as a large integer (Unix timestamp in milliseconds or microseconds), the tool throws an error instead of executing the explain plan.

Steps to reproduce:

  1. Execute a query with a TIMESTAMP WITH TIME ZONE parameter bound as a raw integer (e.g. 825505830505628)
  2. Open the query in the history/log view
  3. Press x or X to run EXPLAIN / EXPLAIN ANALYZE

Error:

rpc error: code = Internal desc = explain: explain: query:
ERROR: date/time field value out of range: "825505830505628" (SQLSTATE 22008)

Expected behavior:

EXPLAIN ANALYZE should execute successfully, the same way the original query did (Duration: 1.2ms, Rows: 1).

Root cause (hypothesis):

The original query runs fine because the driver passes the argument as a native typed value. However, when sql-tap reconstructs the query for EXPLAIN ANALYZE, it substitutes the argument as a plain string literal 825505830505628 into a TIMESTAMP WITH TIME ZONE slot — PostgreSQL then tries to parse it as a date string and fails.

Environment:

  • Tool: sql-tap
  • Database: PostgreSQL
  • Argument value: 825505830505628 (likely Unix epoch in microseconds)

Yes, I used AI to generate text for issue reports :)

Image Image

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions