Skip to content

Fix binding bytes values for VARBINARY columns - #630

Open
hashhar wants to merge 1 commit into
trinodb:masterfrom
hashhar:hashhar/626-varbinary-literal
Open

Fix binding bytes values for VARBINARY columns#630
hashhar wants to merge 1 commit into
trinodb:masterfrom
hashhar:hashhar/626-varbinary-literal

Conversation

@hashhar

@hashhar hashhar commented Aug 18, 2026

Copy link
Copy Markdown
Member

Description

Binary() in trino/dbapi.py called .encode() on every value unconditionally, raising AttributeError for bytes/bytearray/memoryview. It now passes those through as-is.

SQLAlchemy's default literal_processor for binary types also renders values as a quoted string, which breaks for non-UTF-8 bytes. Added a VARBINARY type in trino/sqlalchemy/datatype.py that renders X'<hex>', wired in via dialect.colspecs for reflected and generic LargeBinary/BINARY columns.

Non-technical explanation

You can now write bytes values into a VARBINARY column, whether you're using the raw client or SQLAlchemy.

Release notes

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

* Fix `AttributeError` when binding `bytes` values for `VARBINARY` columns,
  including through SQLAlchemy `LargeBinary` inserts and literal
  compilation.
  ({issue}`626`)

Fixes #626

@cla-bot cla-bot Bot added the cla-signed label Aug 18, 2026
@hashhar
hashhar force-pushed the hashhar/626-varbinary-literal branch from bf6d721 to 56e3ce5 Compare August 18, 2026 14:37
@hashhar
hashhar requested a review from azawlocki-sbdt August 18, 2026 14:38
…paths

Binary() in trino/dbapi.py called .encode() on every value
unconditionally, raising AttributeError for bytes/bytearray/memoryview.
It now passes those through as-is.

SQLAlchemy's default literal_processor for binary types also renders
values as a quoted string, which breaks for non-UTF-8 bytes. Added a
VARBINARY type in trino/sqlalchemy/datatype.py that renders X'<hex>',
wired in via dialect.colspecs for reflected and generic
LargeBinary/BINARY columns.
@hashhar
hashhar force-pushed the hashhar/626-varbinary-literal branch from 56e3ce5 to 861823a Compare August 19, 2026 22:38
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.

bytes cannot be bound: the literal formatter calls .encode() on the value, so VARBINARY is unreachable from Python

1 participant