Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested with statement causes confusion #172

Closed
tipanverella opened this issue Jun 21, 2021 · 6 comments · Fixed by #173
Closed

nested with statement causes confusion #172

tipanverella opened this issue Jun 21, 2021 · 6 comments · Fixed by #173
Labels
Milestone

Comments

@tipanverella
Copy link

I wrote the following test:

def test_create_table_as_select_with_joins_with():
    qry = """
        CREATE table xyz as 
        with sub as (select it_id from internal_table)
        SELECT *
        from (
            with abc as (select * from other_table)
            select name, age, it_id
            from table_z
            join abc on (table_z.it_id = abc.it_id)
        ) as table_a
        join table_b on (table_a.name = table_b.name)
        left join table_c on (table_a.age = table_c.age)
        left join sub on (table_a.it_id = sub.it_id)
        order by table_a.name, table_a.age
        """
    parser = Parser(qry)
    assert set(parser.tables) == set(["xyz", "table_z", "table_b", "table_c", "internal_table", "other_table"])

which the code is unable to pass, as it thinks with in the following sub-query:

from (
  with abc as (select * from other_table)
  select name, age, it_id
  from table_z
  join abc on (table_z.it_id = abc.it_id)
)

is a table.

@tipanverella
Copy link
Author

Please let me know if there is anything I can do to help.

@collerek collerek added the bug label Jun 22, 2021
@collerek collerek added this to the v2.3 milestone Jun 22, 2021
@collerek
Copy link
Collaborator

@tipanverella You just have to put that with everywhere, don't you? 🤣

@macbre
Copy link
Owner

macbre commented Jun 22, 2021

S in SQL does not stand for simple for sure 😉

collerek added a commit that referenced this issue Jun 22, 2021
@tipanverella
Copy link
Author

S in SQL does not stand for simple for sure

It stands for structured, I don't make the rules!!! 🤣

@tipanverella
Copy link
Author

But seriously, please let me know if I can help in any other way. You folks are doing good work.

@collerek
Copy link
Collaborator

@tipanverella fix for this is already in a PR waiting for @macbre review.

You are already helping with those failing edge cases, thanks to you sql-metadata is becoming better and more universal☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants