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

How to properly extract subqueries?

Open minimario opened this issue 2 years ago • 0 comments

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 {}

minimario avatar Jan 22 '23 21:01 minimario