Skip to content

fix(sqlite): transpile Postgres escaped strings as text literals#7678

Closed
russellromney wants to merge 1 commit into
tobymao:mainfrom
russellromney:codex/sqlite-estring-text-literals
Closed

fix(sqlite): transpile Postgres escaped strings as text literals#7678
russellromney wants to merge 1 commit into
tobymao:mainfrom
russellromney:codex/sqlite-estring-text-literals

Conversation

@russellromney
Copy link
Copy Markdown
Contributor

Follow-up to #7677. Postgres E'...' strings parse as ByteString, and SQLite currently has no byte string delimiter, so generation falls back to an unsupported empty string. That drops valid text payloads during Postgres -> SQLite transpilation.

This makes the SQLite generator render ByteString as a normal quoted text literal, preserving the decoded payload.

Examples fixed:

SELECT E'a\nb'         -- SELECT 'a
b'
SELECT E'a\tb'         -- SELECT 'a	b'
SELECT E'a\'b'         -- SELECT 'a''b'
SELECT LENGTH(E'a\nb') -- SELECT LENGTH('a
b')

Checks run:

uv run pytest tests/dialects/test_postgres.py -q -k postgres
uv run pytest tests/dialects/test_sqlite.py -q
uv run ruff check sqlglot/generators/sqlite.py tests/dialects/test_postgres.py
uv run ruff format --check sqlglot/generators/sqlite.py tests/dialects/test_postgres.py

@geooo109
Copy link
Copy Markdown
Collaborator

@russellromney thanks for the PR.

The PR doesn't solve the problem in general right ? it misses cases like r"SELECT e'\x41', length(e'\x41')", SELECT e'\\\x41', length(e'\\\x41'), right ? I'm not sure if they can be solved, because they can also be values of column, so the solution should be compex.

@georgesittas
Copy link
Copy Markdown
Collaborator

It appears that solving the general case would entail pinning down every possible escaped byte sequence and de-escaping it by emitting the actual character. I'm not sure to what extent this is possible or what the end solution will look like, but it seems too complicated.

I'd rather we don't do this right now and call unsupported, which should happen already.

@georgesittas
Copy link
Copy Markdown
Collaborator

Closing this for now, but happy to continue discussing.

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.

3 participants