From bf383b4e28768f927c3a3246a4d534d3535d36c0 Mon Sep 17 00:00:00 2001 From: Bill Sun Date: Mon, 10 Jan 2022 01:47:23 -0500 Subject: [PATCH] added assumption clauses --- mo_sql_parsing/keywords.py | 2 ++ mo_sql_parsing/sql_parser.py | 2 ++ run.py | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mo_sql_parsing/keywords.py b/mo_sql_parsing/keywords.py index 3626698..28b2d28 100644 --- a/mo_sql_parsing/keywords.py +++ b/mo_sql_parsing/keywords.py @@ -21,6 +21,7 @@ DESC = keyword("desc") # SIMPLE KEYWORDS AS = keyword("as").suppress() +ASSUMING = keyword("assuming") ALL = keyword("all") BY = keyword("by").suppress() CAST = keyword("cast") @@ -162,6 +163,7 @@ RESERVED = MatchFirst([ AND, AS, ASC, + ASSUMING, BETWEEN, BY, CASE, diff --git a/mo_sql_parsing/sql_parser.py b/mo_sql_parsing/sql_parser.py index 499e56b..710d6b2 100644 --- a/mo_sql_parsing/sql_parser.py +++ b/mo_sql_parsing/sql_parser.py @@ -407,9 +407,11 @@ def parser(literal_string, ident, sqlserver=False): ) + RB, ) + assumption = (ASSUMING + (ASC|DESC)("assumption")) table_source << Group( ((LB + query + RB) | stack | call_function | var_name)("value") + + Optional(assumption) + Optional(flag("with ordinality")) + Optional(tablesample) + alias diff --git a/run.py b/run.py index 3da498c..45d8da4 100644 --- a/run.py +++ b/run.py @@ -3,4 +3,13 @@ q = 'SELECT p.Name, v.Name FROM Production.Product p JOIN Purchasing.ProductVend res = parser.parse(q) -print(res) \ No newline at end of file +print(res) + +while True: + try: + q = input() + stmts = parser.parse(q) + for s in stmts: + print(s) + except Exception as e: + print(e)