Skip to content

Incorrect Tokenization of Escaped Backslashes in SQL String Literals #814

@dvorst

Description

@dvorst

in the following example

import sqlparse
import sqlparse.tokens as tk

sql = r"SELECT '\\', '\\'"
for s in sqlparse.parse(sql):
    for token_idx, token in enumerate(s.flatten()):
        print(f"{token_idx}: {token.value}")

the literal strings are incorrectly interpreted, as it results in

0: SELECT
1:  
2: '\\', '
3: \
4: \
5: '

The expected result would be:

0: SELECT
1:  
2: '\\'
3: ,
4:  
5: '\\'

sqlparse.version = 0.5.3
python version = 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions