missing tables returned by sql_metadata.get_query_tables
See original GitHub issueHello,
I have 80 long queries, and for 27 of them, results are not correct for “sql_metadata.get_query_tables(ddl)”
Here is an example:
ddl_for_sql_metadata.sql
SELECT
"attr1"
FROM
(
SELECT
"attr2"
FROM
(database1.table1 "aliasTable"
LEFT JOIN (
SELECT
"attr3"
FROM
((
SELECT
"attr4"
FROM
database2.table2
GROUP BY 1, 2, 3, 4
) "aliasTable2"
LEFT JOIN (
SELECT
"attr5"
FROM
database3.table3
GROUP BY 1, 2
) "X" ON ("table"."attr" = "table"."attr"))
) "Y" ON ("table"."attr" = "table"."attr"))
) "Z"
WHERE (myCondition)
GROUP BY 1, 2, 3, 4, 5
Quick way to test:
import sql_metadata
def read_from_file(file_path):
return open(file_path, "r").read()
ddl = read_from_file("ddl_for_sql_metadata.sql")
tables = sql_metadata.get_query_tables(ddl)
print(tables)
It returns only [‘database2.table2’, ‘database3.table3’] and it should return database1.table1
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Why aren't my tables "QueryTables"? - TechNet - Microsoft
According to Microsoft, a QueryTable "Represents a worksheet table built from data returned from an external data source, such as an SQL ...
Read more >macbre/sql-metadata: Uses tokenized query returned ... - GitHub
Uses tokenized query returned by python-sqlparse and generates query metadata. Extracts column names and tables used by the query. Automatically conduct column ...
Read more >How to extract table names and column names from sql query?
This metadata can return column and table names from your supplied SQL query. Here are a couple of example from the sql-metadata github ......
Read more >Find Mismatched SQL Server Data Between Two Tables
In this tip we look at various ways to find mismatched SQL Server data between two tables using LEFT JOIN, EXCEPT, NOT IN...
Read more >Missing Records in Joined Queries. Show All ... - YouTube
Have you ever put two related tables together in a query (like customers and contacts) and you wanted to print out a full...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
🙂
As said above,
WHEN
tests are still marked as skipped -sql-metadata
internals need to mark the table as being used withWITH
keyword and ignore them when returning the list of “real” tables.I’ll add the test that you suggested 👌🏻. In the meantime, stay tuned 🙂
And a test case from the MySQL docs: