Querying the queries: SQL Metaprogramming in Python
summary
Python parses SQL into ASTs represented as nested dictionaries (using libraries like sqloxide) so queries become editable data rather than fragile text. Concrete results: DFS computes subquery depth for CI linting, an AST rewrite wrap denominators in NULLIF() to eliminate divide‑by‑zero errors, auto‑aliasing transforms unnamed aggregates into predictable names, and dependency graphs reveal orphan table E for automated removal. Workflows run deterministically at scale and avoid regex fragility and LLM hallucination.
AI-written summary · about
chapters (10)
- 0:00SQL metaprogramming intro
- 2:09SQL code quality at scale
- 11:18Regex fails for SQL analysis
- 13:03Parsers and ASTs for SQL
- 18:08Dependency graphs with ASTs
- 19:32Nested subquery depth detection
- 21:37Auto-aliasing aggregates
- 26:36NULLIF for denominators
- 30:49Unused CTEs in queries
- 32:53FAQ and LLMs
related talks
32mBecause SQL is everywhere but you don't want to use it
32mUnlearning SQL
18mApparently, you can "debug" your SQL queries
14mAutomated Translation of Functional Big Data Queries to SQL
36mBeyond dbt: Modern SQL Transformation and Lineage with SQLGlot and SQLMesh
26mLSP Demystified - How towrite an LSP server in Python
39mMore Than a Query Language: SQL in the 21st Century
01h 28mSQLAlchemy and You - Making SQL the Best Thing Since Sliced Bread
