sql-metadata
sql-metadata copied to clipboard
How to properly extract subqueries?
I'd like to extract all the subqueries of a query. How can I do that? I tried the below, it didn't work.
query = """SELECT * FROM customers
WHERE id IN (
SELECT customer_id
FROM reservations
WHERE year(reservation_date) = year(now())
GROUP BY customer_id
ORDER BY count(*) DESC
LIMIT 1
);"""
from sql_metadata import Parser
print(Parser(query).subqueries)
# gives {}