Skip to content

fix: emit milliseconds as microseconds on sql.mysql and offset timestamps/times as TIMESTAMPTZ/TIMETZ on sql.postgres - #6593

Merged
max-sixty merged 5 commits into
mainfrom
fix/issue-6592
Nov 21, 2026
Merged

max-sixty merged 5 commits into
mainfrom
fix/issue-6592

Conversation

@prql-bot

@prql-bot prql-bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the two rows of #6592 that translate_literal can settle by itself:

  • sql.mysql: 5milliseconds compiled to INTERVAL 5 MILLISECOND. MySQL has no MILLISECOND unit (its units stop at MICROSECOND), so MySQL 8.0 rejected it with a syntax error. It now compiles to INTERVAL 5000 MICROSECOND. A value that overflows when multiplied by 1000 is a compile error instead of a panic.
  • sql.postgres: @2020-01-01T10:00:00+05:00 compiled to TIMESTAMP '2020-01-01T10:00:00+0500'. Postgres reads that as timestamp without time zone and silently drops the offset. A timestamp ending in Z or a ±HH[:]MM offset now compiles to TIMESTAMPTZ '…'. A time literal such as @10:00+05:00 had the same problem with TIME '…' and now compiles to TIMETZ '…'. Literals without an offset still compile to TIMESTAMP / TIME, and other dialects are unchanged.

The inline tests test_mysql_milliseconds_interval and test_postgres_datetime_with_offset cover both rows. I ran the emitted SQL on local servers. On MySQL 8.0.46, TIMESTAMP '2020-01-01 10:00:00' + INTERVAL 5000 MICROSECOND gives 10:00:00.005000, while the old INTERVAL 5 MILLISECOND fails with ERROR 1064. On Postgres 16 with timezone='UTC', TIMESTAMPTZ '2020-01-01T10:00:00+0500' gives 05:00:00+00, while the old literal gives 10:00:00 with no zone. TIMETZ '10:00+0500' gives 10:00:00+05, while TIME '10:00+0500' gives 10:00:00. The prqlc lib and integration tests pass, and no existing snapshot changed.

Not covered here:

  • The sql.mssql rows (typed-string date literals and INTERVAL) and the sql.sqlite INTERVAL row. Each needs a choice between translating to DATEADD / DATETIME(d, '+3 days') where +/- combine a date and an interval, or reporting a compile error. That choice stays open on the issue.
  • sql.redshift, which is a separate dialect from sql.postgres and still emits TIMESTAMP '…+0500'. I couldn't test how Redshift handles an offset in that literal.

Refs #6592 — automated triage

@max-sixty

Copy link
Copy Markdown
Member

@prql-bot, #6591 merged after this head was reviewed. GitHub now reports Pull Request has merge conflicts for this PR. Please merge current main into the branch, resolve the conflict while retaining both changes, and let CI rerun.

This was written by Codex on behalf of max-sixty

@prql-bot prql-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On sql.postgres, a time literal with an offset has the same problem this PR fixes for timestamps. @10:00+05:00 still compiles to TIME '10:00+0500', because the Literal::Time arm of translate_literal always uses TimezoneInfo::None. With timezone='UTC', Postgres 16 evaluates TIME '10:00+0500' to 10:00:00 and drops the offset, while TIMETZ '10:00+0500' keeps 10:00:00+05. I'll push a fix that applies the same has_utc_offset check to the time arm.

sql.redshift probably has the same gap for timestamps. RedshiftDialect isn't PostgresDialect, so @2020-01-01T10:00:00+05:00 there still compiles to TIMESTAMP '…+0500'. I couldn't test Redshift's handling of an offset in a TIMESTAMP literal here, so I'm leaving that dialect out of this PR.

@prql-bot

Copy link
Copy Markdown
Collaborator Author

Merged current main into the branch as ec6e63f. The only conflict was in CHANGELOG.md: both PRs added an entry at the top of Fixes, and the merge keeps both. gen_expr.rs merged cleanly. prqlc's lib and integration tests pass locally, and every gating check on ec6e63f is green.

@prql-bot prql-bot changed the title fix: emit milliseconds as microseconds on sql.mysql and offset timestamps as TIMESTAMPTZ on sql.postgres fix: emit milliseconds as microseconds on sql.mysql and offset timestamps/times as TIMESTAMPTZ/TIMETZ on sql.postgres Nov 21, 2026
@max-sixty
max-sixty merged commit b9136a6 into main Nov 21, 2026
36 checks passed
@max-sixty
max-sixty deleted the fix/issue-6592 branch November 21, 2026 08:52
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.

2 participants