In response to the recent Google Cloud post "Getting AI to write good SQL" [0] and some comments I've seen here lately [1], I wanted to share an approach that I've found useful for portable, dialect-agnostic SQL generation.<p>tl;dr = Use an abstract Query IR/AST as your generation target, rather than embedding dialect-specific syntax rules. Then render the IR to a target dialect programmatically.<p>Hopefully this is useful for other folks working in the "need to support multiple SQL dialects for my product" space.<p>- [0] <a href="https://news.ycombinator.com/item?id=44009848">https://news.ycombinator.com/item?id=44009848</a><p>- [1] <a href="https://news.ycombinator.com/item?id=43812675">https://news.ycombinator.com/item?id=43812675</a>