Skip to content

fix(sqlalchemy): add literal_processor to TIMESTAMP type#609

Open
q8webmaster wants to merge 1 commit into
trinodb:masterfrom
q8webmaster:fix/timestamp-literal-processor
Open

fix(sqlalchemy): add literal_processor to TIMESTAMP type#609
q8webmaster wants to merge 1 commit into
trinodb:masterfrom
q8webmaster:fix/timestamp-literal-processor

Conversation

@q8webmaster

Copy link
Copy Markdown

Problem

TIMESTAMP.literal_processor() is not implemented, causing a CompileError when
literal_binds=True is used with a datetime.datetime value in a WHERE clause:

sqlalchemy.exc.CompileError: No literal value renderer is available for literal value
"datetime.datetime(2026, 6, 17, 9, 57, 43, 244000)" with datatype DATETIME

Concrete trigger: Apache Superset's select_star() builds a sample query with
WHERE <partition_col> = <latest_partition_value> using literal_binds=True. Any
table with a TIMESTAMP partition column hits this on the table metadata endpoint.

Fix

Add literal_processor to TIMESTAMP emitting a Trino-compatible
TIMESTAMP 'YYYY-MM-DD HH:MM:SS[.mmm]' literal.

Tests

Two unit tests added to tests/unit/sqlalchemy/test_compiler.py:

  • datetime with sub-second precision → TIMESTAMP '2026-06-17 09:57:43.244'
  • datetime without microseconds → TIMESTAMP '2026-06-17 09:57:43'

@cla-bot

cla-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Q8Webmaster.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

SQLAlchemy's DateTime.literal_processor() returns None for Trino's TIMESTAMP
type, causing a CompileError when literal_binds=True is used and a datetime
value appears in a WHERE clause (e.g. Superset's select_star partition filter).

Add a literal_processor to TIMESTAMP that emits a Trino-compatible
TIMESTAMP 'YYYY-MM-DD HH:MM:SS[.mmm]' literal.
@q8webmaster q8webmaster force-pushed the fix/timestamp-literal-processor branch from 60ae3e8 to 1f79e64 Compare June 17, 2026 14:58
@cla-bot

cla-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant