Comma Separator Before Field Name Or After?

Before! The comma separator before field name is always preferred. There, that was easy.

You’ve come here to either win an argument with a coworker — in which case I hope you’re here to find proof for having the comma separator before field names, or you’re doing it wrong — or you’re here to learn. In either case, the comma comes before field names. So, allow me to justify when and, more importantly, why I use one variation over the other:

Example of both comma separators

You’ll notice that both these queries are very much identical, with the exception of the placement of the delimiting comma between each field in the select clause of course.

There are two schools of thought here:

  1. Whether you add columns to the bottom or the top of a query can impact how the comma placement affects your query writing style.
  2. Comma troubleshooting is important and arguably, locating a missing comma is important.

If you add columns to your query, whether it’s the top or the bottom of the field stack, it can create inconvenience with either practice. However, more importantly, I like to think that the second point is more valid: When looking at a query holistically it is easy to discern if you’re missing a comma when the field separator is in the front versus at the end of the field name.

When looking at a query holistically, it is easier to spot a missing comma when the field separator is in the front of the field name versus at the end.

This could be one of the biggest arguments among data professionals. It is one that seems trivial but has roots that extend from the first query to every query we write every day thereafter. What’s your preference?