PostgreSQL Online Editor
Write and run real PostgreSQL queries online for free. CodeCompiler runs PostgreSQL (PGlite) directly in your browser, so every PostgreSQL feature — SERIAL, JSONB, window functions, CTEs — works exactly as on a server. Each run starts with a fresh, empty database.
Create a table and insert rows
CREATE TABLE employees (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
dept TEXT,
salary NUMERIC(10, 2)
);
INSERT INTO employees (name, dept, salary) VALUES
('Asha', 'Engineering', 90000),
('Ravi', 'Sales', 60000),
('Meera', 'Engineering', 95000);Query, filter and sort
SELECT name, salary FROM employees WHERE dept = 'Engineering' ORDER BY salary DESC;
Aggregate with GROUP BY
SELECT dept, COUNT(*) AS people, AVG(salary)::NUMERIC(10,2) AS avg_salary FROM employees GROUP BY dept;
Window functions
SELECT name, dept, salary,
RANK() OVER (PARTITION BY dept ORDER BY salary DESC) AS dept_rank
FROM employees;JSONB
SELECT '{"lang": "sql", "tags": ["db", "pg"]}'::jsonb -> 'tags' ->> 0 AS first_tag;
