Skip to main content
Recently used

Online PostgreSQL Editor

Edit PostgreSQL online with syntax highlighting in your browser. Free PostgreSQL editor for scripts, configs, and snippets on ConversionTab.

Need custom conversion?

Completions appear as you type; press Ctrl+Space to open the list. Tab expands snippets where available. Find: Ctrl+F (Cmd+F on Mac). Format: toolbar button or Ctrl+Shift+B for supported languages.

Choose editor font size in pixels

Compose and document PostgreSQL queries with a focused editor—ideal for reviews and teaching.

Good for drafting queries you will paste into a DB client—this page does not open a live database.

Drafting PostgreSQL for tickets, reviews, and teaching—without connecting this page to a live database.

Write readable PostgreSQL with clear aliases, explicit joins, and a LIMIT while you explore. Prefer listing columns over SELECT * in shared snippets so reviews stay focused.

Keep schema changes and destructive statements out of casual scratchpads—pair drafts with your migration process. Format long queries before review so diffs stay reviewable.

Call out the dialect in a comment (Postgres vs MySQL vs SQL Server) when syntax differs—window functions, LIMIT/TOP, and JSON operators are common tripwires.

When you need a structure check on related tabular data, ConversionTab’s CSV/JSON tools and validators can help after you export results from your DB client.

Stable link for this mode: /code-editor/pgsql

Open this PostgreSQL editor, paste or type in the Ace buffer, use find/replace and theme/font controls, then download when ready. Theme choices may stick in local storage on this device—it is not a cloud project.

Editing stays in your browser for normal use (no account required). Do not paste production secrets; save important work to your own repo or encrypted store.

Copy a starter into the editor, rename symbols to match your project, then download. These are teaching/review snippets—not a full app scaffold.

Filtered SELECT

-- PostgreSQL
SELECT id, email, created_at
FROM users
WHERE active = TRUE
  AND created_at >= CURRENT_DATE - INTERVAL '7 days'
ORDER BY created_at DESC
LIMIT 50;

JOIN + aggregate

SELECT u.id, COUNT(o.id) AS orders
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
GROUP BY u.id
HAVING COUNT(o.id) > 0;

Window function

SELECT id,
       amount,
       SUM(amount) OVER (PARTITION BY user_id ORDER BY created_at) AS running
FROM payments;

Common PostgreSQL patterns for variables, control flow, and comments. Adjust style to your team’s formatter before you commit.

Variables (session)

-- PostgreSQL
SET @limit = 100;
PREPARE stmt FROM 'SELECT * FROM t LIMIT ?';

Conditional filters

SELECT *
FROM products
WHERE (:category IS NULL OR category = :category)
  AND price BETWEEN :min AND :max;

CTE chain

WITH base AS (
  SELECT * FROM events WHERE ts > NOW() - INTERVAL '1 day'
)
SELECT * FROM base WHERE type = 'purchase';

Comments

-- line comment
/* block comment */

Reporting query with CTE

-- PostgreSQL: staged report
WITH daily AS (
  SELECT DATE(created_at) AS d, COUNT(*) AS n
  FROM events
  GROUP BY 1
)
SELECT d, n, SUM(n) OVER (ORDER BY d) AS running
FROM daily
ORDER BY d DESC
LIMIT 30;

Safe migration sketch

-- PostgreSQL: additive change
BEGIN;
  ALTER TABLE users ADD COLUMN IF NOT EXISTS locale TEXT;
  UPDATE users SET locale = 'en' WHERE locale IS NULL;
COMMIT;

Does PostgreSQL run on ConversionTab servers?
No. Download the query and run it in your database client. This page does not open a live DB connection.
Is my code uploaded while I type?
Normal editing stays in the browser. You do not need an account to draft or download.
Can I change theme and font size?
Yes—use the toolbar above the editor. Preferences can persist in local storage on this device.
When should I use an IDE instead?
Use your IDE for large projects, debugging, secrets, and production builds. This page is for short drafts and reviews.