Skip to content

Add literal_processor to TIMESTAMP, TIME and DATE SQLAlchemy types - #631

Open
hashhar wants to merge 2 commits into
trinodb:masterfrom
hashhar:hashhar/609-timestamp-literal-processor
Open

Add literal_processor to TIMESTAMP, TIME and DATE SQLAlchemy types#631
hashhar wants to merge 2 commits into
trinodb:masterfrom
hashhar:hashhar/609-timestamp-literal-processor

Conversation

@hashhar

@hashhar hashhar commented Aug 18, 2026

Copy link
Copy Markdown
Member

literal_binds=True raised CompileError for TIMESTAMP and TIME columns and compiled DATE to a bare varchar literal that Trino rejects. Superset's select_star() hits this on partition columns.

The temporal formatting moves into a shared trino.temporal module used by both the DBAPI and SQLAlchemy paths so a value compiles to the same SQL:

  • Named zones (ZoneInfo, pytz) render as zone names (Asia/Kolkata) instead of fixed offsets.
  • A ZoneInfo-aware time keeps its zone offset instead of silently dropping it.
  • Sub-minute UTC offsets raise instead of silently shifting the instant.
  • Wrong Python types raise CompileError instead of turning into bad SQL.

Covers reflected columns only. The generic SQLAlchemy DateTime/Time/Date types stay uncovered (pre-existing gap).

Release notes

(x) Release notes are required, with the following suggested text:

* Fix compiling `literal_binds` for `TIMESTAMP`, `TIME` and `DATE` columns in
  the SQLAlchemy dialect.
  ({issue}`609`)

@cla-bot cla-bot Bot added the cla-signed label Aug 18, 2026
@hashhar
hashhar force-pushed the hashhar/609-timestamp-literal-processor branch from 0d300f5 to 916e775 Compare August 18, 2026 14:52
Move the datetime, time, and date branches of _format_prepared_param
verbatim into trino.temporal.format_temporal_literal. The rendered
SQL is unchanged. A later commit reuses the function from the
SQLAlchemy dialect.
TIMESTAMP and TIME had no literal_processor, so literal_binds=True
raised CompileError for those columns. DATE columns compiled to a
bare varchar literal that Trino rejects. Apache Superset's
select_star() hits the failure when it reflects partition columns.

The new literal processors delegate to trino.temporal, which the
DBAPI parameter formatter already uses, so a value compiles to the
same SQL on both paths.

The shared renderer gains several fixes. Named zones render as zone
names for pytz as well as zoneinfo. Fixed offsets render as +HH:MM
instead of tzname() output. Years below 1000 render zero-padded on
every platform. Sub-minute UTC offsets raise an error because a
Trino literal cannot represent them. In SQLAlchemy, values of the
wrong Python type raise CompileError instead of turning into bad SQL.
@hashhar
hashhar force-pushed the hashhar/609-timestamp-literal-processor branch from 916e775 to 0da6bad Compare August 19, 2026 22:15
@hashhar hashhar changed the title Add literal_processor to TIMESTAMP and TIME SQLAlchemy types Add literal_processor to TIMESTAMP, TIME and DATE SQLAlchemy types Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant