Skip to content

Postgres: Support U&"..." quoted identifiers and UESCAPE clause - #2509

Open
BenSatori wants to merge 1 commit into
apache:mainfrom
BenSatori:postgres-unicode-parsing
Open

Postgres: Support U&"..." quoted identifiers and UESCAPE clause#2509
BenSatori wants to merge 1 commit into
apache:mainfrom
BenSatori:postgres-unicode-parsing

Conversation

@BenSatori

Copy link
Copy Markdown
Contributor

Example

Before this PR, none of these valid Postgres queries parsed:

SELECT 1 AS U&"d\0061ta", * from customers;
SELECT * from U&"c\0075stomers" limit 10;
SELECT * from U&"c!0075stomers" UESCAPE '!' limit 10;

U&"..." Unicode-escaped quoted identifiers were not tokenized at all (only the U&'...' string literal form was supported), and the UESCAPE '<char>' clause that can follow either a U&'...' string or a U&"..." identifier to override the default \ escape character was not implemented, even though the UESCAPE keyword already existed in keywords.rs.

Fix

U&"..." identifiers now tokenize into a regular quoted identifier (decoded, e.g. U&"d\0061ta" -> "data"), and both U&'...' and U&"..." now support an optional trailing UESCAPE '<char>' clause.

See the Postgres docs (identifiers) and UESCAPE docs (escape clause). Relates to #1354, which added the U&'...' string literal support this PR extends.

This PR was authored with the assistance of GitHub Copilot.

PostgreSQL supports Unicode-escaped quoted identifiers (U&"...") in
addition to Unicode string literals (U&'...'), and both accept an
optional trailing UESCAPE '<char>' clause to override the default
backslash escape character. Neither was previously supported by the
parser.

See https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Co-authored-by: GitHub Copilot <copilot@github.com>
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.

1 participant