5

I am looking for a command line SQL formatter = SQL prettifier = SQL beautifier (offline, not an online formatter) for Mac. The goal is to run it on the command line and also inside the editor (Emacs) for SQL files under a few thousand lines.

Related:

Most of the posts below do not answer my question because of one or more of the following reasons: they were closed before they could accumulate enough quality answers; they are old; they refer mostly to online tools; they are related to other languages/operating systems:

1

3 Answers 3

4
+50

Prettier integrates with editors and Git, has a command-line interface, and a SQL plugin.

3

Try out sqlformat, shipped with sqlparse Python library. The easiest way to install it is using pipx:

pipx install sqlparse

Here is an example of running it:

$ echo "sElECt address,country,fName FrOm tbl_Name Where f1=true aNd fname iS nOt null oRdEr bY fName aSc" \
   | sqlformat - --reindent --keywords upper
SELECT address,
       country,
       fName
FROM tbl_Name
WHERE f1=TRUE
  AND fname IS NOT NULL
ORDER BY fName ASC

To run it on a file, pass the file name instead of - :

sqlformat example.sql --reindent --keywords upper
1

sleek might be worth a look. It's not as configurable as the more mature tools here, but its SQL style is excellent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.