More Prettier SQL
May 29th, 2019
I hate reading SQL. I hate it more than writing it. When you’re reading SQL, it’s inevitably because you’ve found a bug in someone else’s query. Hell is other people’s code. SQL is no exception.
Writing SQL, I tend to think a lot about indentation because it lends elevation to a query. I end up referring back to other parts of my query (usually CTEs) and when a SQL query hits 100s of lines, searching through the query can be relatively painful. Obviously, SQL prettifiers exist for this reason, but I wonder if we could go beyond indentation for organization. For instance, contextual highlighting (whether through color or bolding) of relevant column or table aliases based on where my cursor. Imagine if, when writing a
group by, the
select column expressions were bolded. Or perhaps different (though subtle) changes in background color might help break up a querypad: not only between statements, but even between subqueries.