Skip to content

Fix DataGrip Format SQL – Not Formatting or Wrong Style

DodaTech Updated 2026-06-24 3 min read

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.

Customise the formatter:

  1. Settings β†’ Editor β†’ Code Style β†’ SQL β†’ [your dialect, e.g. MySQL]
  2. Case tab:
    • Keywords: UPPER
    • Functions: UPPER
    • Types: UPPER
    • Identifiers: LOWER (or leave as is)
  3. Sets tab:
    • β˜‘ Clause on separate line
    • β˜‘ Indent clause body
    • β˜‘ ELSE on new line
  4. Spacing tab:
    • β˜‘ Before commas β†’ unchecked
    • β˜‘ After commas β†’ checked
  5. Wrapping tab:
    • Right margin: 120
    • Wrap on typing: By 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

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to 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

**Q: Can I format only a selected block of SQL?**

A: Yes β€” highlight the lines and press Ctrl+Alt+L. Only the selection is reformatted.

**Q: How do I prevent DataGrip from breaking long lines?**

A: In Code Style β†’ SQL β†’ Wrapping, set Right margin to a large value like 999 and choose Wrap on typing: Do not wrap.

**Q: Does formatting change my SQL's behaviour?**

A: No β€” SQL formatting is purely cosmetic. The parser reconstructs the AST and re‑renders it.

**Q: Why does formatting affect my string literals?**

A: It shouldn't. Check that you aren't running a Code Cleanup action that also modifies code β€” use Reformat Code specifically.


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