Skip to content

Commit

Permalink
add test_as_was_preceded_by_with_query
Browse files Browse the repository at this point in the history
  • Loading branch information
MiuNice authored Dec 6, 2023
1 parent 2a9823c commit 0af4803
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/test_with_statements.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from sql_metadata import Parser
from sql_metadata.keywords_lists import QueryType

Expand Down Expand Up @@ -493,3 +495,35 @@ def test_identifier_syntax():

assert parser.tables == ["hits"]
assert parser.columns == ["EventDate", "EventTime", "ts_upper_bound"]


def test_as_was_preceded_by_with_query():
# fix
# When 'with .* as (.*) as ...', it should prompt an error instead of an infinite loop.
query = """
WITH
t1 (c1, c2) AS (SELECT * FROM t2) AS a1
SELECT 1;
"""
parser = Parser(query)
with pytest.raises(ValueError, match="This query is wrong"):
parser.tables

query = """
WITH
t1 as (SELECT * FROM t2) AS
SELECT 1;
"""
parser = Parser(query)
with pytest.raises(ValueError, match="This query is wrong"):
parser.tables

query = """
WITH
'2023-01-01' as (date) AS
SELECT 1;
"""
parser = Parser(query)
with pytest.raises(ValueError, match="This query is wrong"):
parser.tables

0 comments on commit 0af4803

Please sign in to comment.