summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2017-05-25 08:52:13 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2017-05-25 08:52:13 +0200
commitdc788ab5b1af2e2a4a988b31a09d8d6656853f76 (patch)
treeca574d197ebe87165e5407c8090cfdd50d00b171
parent0b467460762c51d5480271a7010c5936a116317b (diff)
downloadsqlparse-dc788ab5b1af2e2a4a988b31a09d8d6656853f76.tar.gz
Recognize MySQL table names starting with digits (fixes #337).
-rw-r--r--CHANGELOG1
-rw-r--r--sqlparse/keywords.py4
-rw-r--r--tests/test_parse.py7
3 files changed, 8 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 1ce04eb..c61b3d8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ Enhancements
Bug Fixes
+* Fix parsing of MySQL table names starting with digits (issue337).
* Fix detection of identifiers using comparisons (issue327).
diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py
index 6a214f1..92da63e 100644
--- a/sqlparse/keywords.py
+++ b/sqlparse/keywords.py
@@ -60,7 +60,7 @@ SQL_REGEX = {
(r'-?0x[\dA-F]+', tokens.Number.Hexadecimal),
(r'-?\d*(\.\d+)?E-?\d+', tokens.Number.Float),
(r'-?\d*\.\d+', tokens.Number.Float),
- (r'-?\d+', tokens.Number.Integer),
+ (r'-?\d+(?![_A-Z])', tokens.Number.Integer),
(r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single),
# not a real string literal in ANSI SQL:
@@ -77,7 +77,7 @@ SQL_REGEX = {
(r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL),
(r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),
- (r'[_A-Z][_$#\w]*', is_keyword),
+ (r'[0-9_A-Z][_$#\w]*', is_keyword),
(r'[;:()\[\],\.]', tokens.Punctuation),
(r'[<>=~!]+', tokens.Operator.Comparison),
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 0632889..4ba6ca1 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -135,11 +135,14 @@ def test_quoted_identifier():
assert t[2].get_real_name() == 'y'
-@pytest.mark.parametrize('name', ['foo', '_foo'])
+@pytest.mark.parametrize('name', [
+ 'foo', '_foo', # issue175
+ '1_data', # valid MySQL table name, see issue337
+])
def test_valid_identifier_names(name):
- # issue175
t = sqlparse.parse(name)[0].tokens
assert isinstance(t[0], sql.Identifier)
+ assert t[0].get_name() == name
def test_psql_quotation_marks():