Formatador SQL
Formate, indente e minifique SQL para PostgreSQL, MySQL e SQLite, com palavras-chave em maiúsculas e uma cláusula por linha.
Roda totalmente no seu navegador: nada do que você cola é enviado.
SELECT c.id, c.email, count(o.id) AS order_count, sum(o.total) AS lifetime_value FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE o.created_at >= '2026-01-01' AND o.status <> 'refunded' GROUP BY c.id, c.email HAVING count(o.id) > 3 ORDER BY lifetime_value DESC LIMIT 25;
Uma cláusula por linha, com listas de SELECT, GROUP BY, ON CONFLICT e subconsultas indentadas. Palavras-chave de PostgreSQL, MySQL e SQLite são reconhecidas.
Referência de formatação SQL
referência rápida- SELECT … FROM … WHERE
- A ordem de cláusulas que o SQL espera. Uma cláusula por linha é o que torna uma consulta longa legível em uma revisão ou log.
- LEFT JOIN … ON
- Mantém todas as linhas da tabela da esquerda e preenche com NULL as sem correspondência; INNER JOIN as descarta.
- GROUP BY / HAVING
- HAVING filtra depois da agregação e WHERE antes, por isso WHERE não pode usar o resultado de COUNT ou SUM.
- WITH name AS (…)
- Expressão de tabela comum. A maioria dos planejadores a incorpora, mas mantém a consulta longa legível; use RECURSIVE para autorreferência.
- ON CONFLICT (key) DO UPDATE
- Upsert do PostgreSQL e do SQLite. O MySQL usa INSERT … ON DUPLICATE KEY UPDATE.
- LIMIT n OFFSET m
- Pagina resultados, mas prefira um cursor por chave (WHERE id > last_id) quando o deslocamento passa de alguns milhares de linhas.
Guias de sintaxe de SQL
Todos os guias de SQLPostgres RLS 42P17: infinite recursion detected in policy
A policy on members that reads members re-enters itself. One security definer function with a pinned search_path ends the recursion and leaves the rest of the policy intact.
SQLPgBouncer Transaction vs Session Pooling: What Breaks
Port 6543 hands out a server connection per transaction, so prepared statements, SET, LISTEN and cursors stop behaving. Driver-level settings for each stack.
SQLZero-Downtime Postgres Migrations: lock_timeout and NOT VALID
One ALTER TABLE waiting behind a slow SELECT blocks every query that arrives after it. The timeout-retry loop, NOT VALID constraints and CONCURRENTLY index rules.
SQLPostgres JSONB Indexing: GIN vs Expression B-Tree
GIN answers containment, not equality, and an expression B-tree is the reverse. Choose by operator, match the expression exactly, and prove it with EXPLAIN.