sql-metadata icon indicating copy to clipboard operation
sql-metadata copied to clipboard

get_query_tables get not only table names but sometimes column names as well

Open horvatha opened this issue 2 years ago • 0 comments

If I run get_query_tables with this string as an argument, I think only TABLE1 should be in the value it returns, and MTYPE shouldn't be there.

SELECT   *
FROM     TABLE1
WHERE
    SNAPSHOTDATE = (SELECT MAX(SNAPSHOTDATE) FROM TABLE1)
    AND (MTYPE NOT IN ('Item1', 'Item2'))

I would assume, that this function run without assertion error.

from sql_metadata.compat import get_query_tables

def test_get_query_tables():
    sql = """
SELECT   *
FROM     TABLE1
WHERE
    SNAPSHOTDATE = (SELECT MAX(SNAPSHOTDATE) FROM TABLE1)
    AND (MTYPE NOT IN ('Item1', 'Item2'))
    """
    assert 'MTYPE' not in get_query_tables(sql)

I've installed sql_metadata==2.10.0 with pip and tested it with Python 3.11.0rc1.

horvatha avatar Dec 16 '23 16:12 horvatha