Highly customized SQL formatter?

I’ve been handed off some fairly lengthy queries that I’m struggling to read. As with most people who use SQL extensively, I’ve got a couple of my own conventions that I use to aid readability. For example, a query which is given to me like this:

SELECT t1.column_a, t2.column_b score
FROM schema.table_name t1
INNER JOIN schema.table_name t2
ON t1.id = t2.id;

I would normally write as

SELECT t1."COLUMN_A", t2."COLUMN_B" AS "SCORE"
FROM SCHEMA.TABLE_NAME t1
INNER JOIN SCHEMA.TABLE_NAME t2
ON t1."ID" = t2."ID";

The main conventions of my style are:

  • Schema and table name are always upper case
  • Table aliases are always lower case
  • Column names are always upper case and encased in quotes

The reason that I do this is I find it visually easier to distinguish things w/ the upper and lower case conventions, as well as the fact that using quotes around column names changes the text color, which again aids in readability (at least for me).

I recognize that this is a highly personalized approach, but I guess I’m wondering if there are any formatters out there that can accomplish this for me? I have a lot of very long queries that I need to work with and am hoping to avoid having to reformat all of them manually.

submitted by /u/unicornpoacher2k
[link] [comments]


Go to Source of this post
Author Of this post: /u/unicornpoacher2k
Title Of post: Highly customized SQL formatter?
Author Link: {authorlink}