Fix DataGrip Format SQL β Not Formatting or Wrong Style
In this tutorial, you'll learn about Fix DataGrip Format SQL. We cover key concepts, practical examples, and best practices.
You write a monstrous SQL query in DataGrip, press Ctrl+Alt+L to format it β and nothing happens. Or it reformats into something even messier: everything on one line, joins indented wrong, uppercase turned to lowercase.
Wrong β
select users.name, orders.total, orders.created_at
from users
inner join orders on users.id = orders.user_id
where orders.total > 100
order by orders.created_at desc;
You press Ctrl+Alt+L and get:
select users.name, orders.total, orders.created_at from users inner join orders on users.id = orders.user_id where orders.total > 100 order by orders.created_at desc;
One long line β unreadable.
Or:
SELECT users.name,
orders.total,
orders.created_at
FROM users
INNER JOIN orders ON users.id = orders.user_id
WHERE orders.total > 100
ORDER BY orders.created_at DESC;
The second line lacks proper indentation.
Right β
Customise the formatter:
- Settings β Editor β Code Style β SQL β [your dialect, e.g. MySQL]
- Case tab:
- Keywords:
UPPER - Functions:
UPPER - Types:
UPPER - Identifiers:
LOWER(or leave as is)
- Keywords:
- Sets tab:
- β Clause on separate line
- β Indent clause body
- β ELSE on new line
- Spacing tab:
- β Before commas β unchecked
- β After commas β checked
- Wrapping tab:
- Right margin:
120 - Wrap on typing:
By margin
- Right margin:
Now format (Ctrl+Alt+L):
SELECT
users.name,
orders.total,
orders.created_at
FROM users
INNER JOIN orders ON users.id = orders.user_id
WHERE orders.total > 100
ORDER BY orders.created_at DESC;
If your team uses a different style (e.g. tabs vs spaces), set Indent β Use tab character and Tab size: 4.
Root Cause
DataGrip's default formatter uses a conservative style (inline clauses, no indent). It also honours the .editorconfig from the project if present. Without customisation, the result often clashes with team conventions.
Prevention
- Share formatter config: File β Export β Code Style Settings β commit the JAR to your project repo.
- Use an EditorConfig file (
.editorconfig) in the project root so formatting is consistent across IDEs. - Format on save: Settings β Tools β Actions on Save β β Reformat code.
- Create a separate Scheme per SQL dialect (MySQL, PostgreSQL, BigQuery) in Code Style settings.
Common Mistakes with format sql
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad
These mistakes appear frequently in real-world DATAGRIP code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
SQL formatting and team standards are covered in the DodaTech DataGrip Pro course.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro