Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Cannot recognize literals when using with an operator #139

Closed
zhangysh1995 opened this issue Aug 2, 2020 · 2 comments
Closed

Cannot recognize literals when using with an operator #139

zhangysh1995 opened this issue Aug 2, 2020 · 2 comments
Labels
ARCHIVED - See README ARCHIVED - See README.md

Comments

@zhangysh1995
Copy link

Test case:

from moz_sql_parser import parse, format

# works
s = "select '123';"
print(s)
tokens = parse(s)
print(tokens)
back = format(tokens)
print(back)

s = 'SELECT `col_double_undef_signed` FROM `table_10_binary_undef` WHERE (8221 <> "back") ORDER BY `col_char(20)_key_signed`;'
print(s)
#  doesn't work, "back" is not parsed to literal
tokens = parse(s)
print(tokens)
back = format(tokens, ansi_quotes=False)
print(back)

Output:

select '123';
{'select': {'value': {'literal': '123'}}}
SELECT '123'
SELECT `col_double_undef_signed` FROM `table_10_binary_undef` WHERE (8221 <> "back") ORDER BY `col_char(20)_key_signed`;
# "back" is not a literal
{'select': {'value': 'col_double_undef_signed'}, 'from': 'table_10_binary_undef', 'where': {'neq': [8221, 'back']}, 'orderby': {'value': 'col_char(20)_key_signed'}}
SELECT `col_double_undef_signed` FROM `table_10_binary_undef` WHERE (8221 <> `back`) ORDER BY `col_char(20)_key_signed`
@zhangysh1995
Copy link
Author

zhangysh1995 commented Aug 2, 2020

I could locate the root cause here and here.
It seems only single quote is recognized as a literal.

# STRINGS, NUMBERS, VARIABLES
sqlString = Regex(r"\'(\'\'|\\.|[^'])*\'").addParseAction(to_string)

@klahnakoski
Copy link
Contributor

@zhangysh1995 yes, only the single quote can be used for literals; double quotes are for identifiers

@cknowles-admin cknowles-admin added the ARCHIVED - See README ARCHIVED - See README.md label Jun 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ARCHIVED - See README ARCHIVED - See README.md
Projects
None yet
Development

No branches or pull requests

3 participants