summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Bodley <john.bodley@airbnb.com>2020-01-20 13:09:52 -0800
committerAndi Albrecht <albrecht.andi@gmail.com>2020-02-02 21:19:41 +0100
commit44eacf2e2f4a4255829109a5e67e0c1d2af542da (patch)
treef3f01426f2caaa15096adca34509b584654e5623
parentaaf5403f05e2cdb4f36a507b92e039c8cc2016a0 (diff)
downloadsqlparse-44eacf2e2f4a4255829109a5e67e0c1d2af542da.tar.gz
[fix] Fixing typed literal regression
-rw-r--r--sqlparse/engine/grouping.py2
-rw-r--r--sqlparse/sql.py5
-rw-r--r--tests/test_grouping.py6
3 files changed, 9 insertions, 4 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 3f06e8a..b634128 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -108,7 +108,7 @@ def group_typed_literal(tlist):
# https://www.postgresql.org/docs/9.1/datatype-datetime.html
# https://www.postgresql.org/docs/9.1/functions-datetime.html
def match(token):
- return token.match(*sql.TypedLiteral.M_OPEN)
+ return imt(token, m=sql.TypedLiteral.M_OPEN)
def match_to_extend(token):
return isinstance(token, sql.TypedLiteral)
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 77f980b..a942bcd 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -491,10 +491,9 @@ class IdentifierList(TokenList):
class TypedLiteral(TokenList):
"""A typed literal, such as "date '2001-09-28'" or "interval '2 hours'"."""
- M_OPEN = T.Name.Builtin, None
+ M_OPEN = [(T.Name.Builtin, None), (T.Keyword, "TIMESTAMP")]
M_CLOSE = T.String.Single, None
- M_EXTEND = T.Keyword, (
- "DAY", "HOUR", "MINUTE", "MONTH", "SECOND", "TIMESTAMP", "YEAR")
+ M_EXTEND = T.Keyword, ("DAY", "HOUR", "MINUTE", "MONTH", "SECOND", "YEAR")
class Parenthesis(TokenList):
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 8162362..6b5bb68 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -33,6 +33,12 @@ def test_grouping_assignment(s):
assert isinstance(parsed.tokens[0], sql.Assignment)
+@pytest.mark.parametrize('s', ["x > DATE '2020-01-01'", "x > TIMESTAMP '2020-01-01 00:00:00'"])
+def test_grouping_typed_literal(s):
+ parsed = sqlparse.parse(s)[0]
+ assert isinstance(parsed[4], sql.TypedLiteral)
+
+
@pytest.mark.parametrize('s, a, b', [
('select a from b where c < d + e', sql.Identifier, sql.Identifier),
('select a from b where c < d + interval \'1 day\'', sql.Identifier, sql.TypedLiteral),