Formateador SQL
Formatea, indenta y minimiza SQL para PostgreSQL, MySQL y SQLite, con palabras clave en mayúsculas y una cláusula por línea.
Se ejecuta por completo en tu navegador: nada de lo que pegues se sube.
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;
Una cláusula por línea, con listas de SELECT, GROUP BY, ON CONFLICT y subconsultas indentadas. Se reconocen palabras clave de PostgreSQL, MySQL y SQLite.
Referencia de formato SQL
referencia rápida- SELECT … FROM … WHERE
- El orden de cláusulas que espera SQL. Una cláusula por línea es lo que hace legible una consulta larga en una revisión o en un log.
- LEFT JOIN … ON
- Conserva todas las filas de la tabla izquierda y rellena con NULL las que no coinciden; INNER JOIN las descarta.
- GROUP BY / HAVING
- HAVING filtra después de agregar y WHERE antes, por eso WHERE no puede usar el resultado de COUNT o SUM.
- WITH name AS (…)
- Expresión de tabla común. La mayoría de planificadores la inserta en la consulta, pero mantiene legible una consulta larga; añade RECURSIVE para autorreferencia.
- ON CONFLICT (key) DO UPDATE
- Upsert de PostgreSQL y SQLite. MySQL usa INSERT … ON DUPLICATE KEY UPDATE.
- LIMIT n OFFSET m
- Pagina resultados, pero conviene un cursor por clave (WHERE id > last_id) cuando el desplazamiento supera unos miles de filas.
Guías de sintaxis de SQL
Todas las guías 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.