top | item 37215909

(no title)

bot347851834 | 2 years ago

I'm of the same opinion. I always wonder why SQL formatters do this. Is it because it's easier to diff queries with versioning tools? Because to me it's definitely not for legibility. The example shown here isn't even that bad compared to what I see regularly. We've got quiet a few queries longer than 100 sanely written lines running in BigQuery, sometimes I missclick the "format query" option and it always makes me wonder who the hell enjoys scrolling so much because suddenly the line count increases by an order or magnitude or more and the lines aren't much longer than 20 or so characters.

discuss

order

natpalmer1776|2 years ago

I think formatters are generally written by people who value consistency above other criteria, as many of the general conventions used when handwriting queries tend to break down as the complexity of the query increases. With these formatters I imagine complex queries would render in a more 'consistent' manner.

DougMerritt|2 years ago

Yes, and that tends to be the case with formatters for programming languages in general.

adamrezich|2 years ago

I agree that the example input is more readable than the output, but I also think it's a bad example of messy SQL. sometimes it's nice to use a tool like this to break down a complex, appended-to-by-multiple-authors-over-the-years query just so you can understand the logic (and sometimes find unexpected logic bugs that nobody noticed before). at least, that's been my experience.

johnnyworker|2 years ago

I make SQL queries even bigger, and for me it's not so much about reading but being able to copy and paste bits of it easily (easy meaning any line is just one "token"), to modify it or use parts of it elsewhere.