PostgreSQL playground: run Postgres online
A real PostgreSQL engine (PGlite) running in your browser tab, with sample databases loaded. Write a query, press Run, and see the result. Below: what this PostgreSQL can and can't do, and five queries that only work in PostgreSQL.
PostgreSQL 18.6 (PGlite 0.5.16), read from the engine itself when this page was built.
Each run starts from a fresh copy of the sample data. To try your own tables, put CREATE TABLE, INSERT and your SELECT in one run.
What works here
- ✓CTEs, including WITH RECURSIVE
- ✓Window functions with frames (ROWS BETWEEN …)
- ✓generate_series for numbers and dates
- ✓DISTINCT ON, FILTER (WHERE …) and ILIKE
- ✓Date functions: date_trunc, EXTRACT, to_char, intervals
- ✓JSON functions and operators (json_build_object, ->>)
- ✓Arrays and array_agg
- ✓CREATE TABLE, INSERT, UPDATE, DELETE and ON CONFLICT upserts
What doesn't
- –No extensions are loaded (no PostGIS or pgvector)
- –One connection: no concurrent sessions, locks or LISTEN/NOTIFY
- –No server settings, users or roles
- –Every run starts from a fresh copy of the data and is rolled back afterwards
Five queries only PostgreSQL runs
Each one was run on both engines when this page was built: it works in PostgreSQL and fails in SQLite. More side by side in PostgreSQL vs SQLite.
The priciest item per category with DISTINCT ON
DISTINCT ON keeps the first row of each group in ORDER BY order. SQLite has no DISTINCT ON; there you'd use ROW_NUMBER().
SELECT DISTINCT ON (category) category, name, price FROM menu_items ORDER BY category, price DESC;Result: 4 rows
category name price dessert Tiramisu 6.5 drink Lemon Soda 3 pizza BBQ Meteor 15.5 side Wings 8.5 Data: Rocket PizzaA calendar of days with generate_series
generate_series makes rows out of thin air, here one per day. LEFT JOIN orders to it to count days with no orders. SQLite here has no generate_series.
SELECT d::date AS day, COUNT(o.id) AS orders FROM generate_series(DATE '2026-03-01', DATE '2026-03-07', INTERVAL '1 day') AS d LEFT JOIN orders o ON o.ordered_on = d::date GROUP BY d ORDER BY d;Result: 7 rows
day orders 2026-03-01 2 2026-03-02 0 2026-03-03 1 2026-03-04 1 2026-03-05 2 2026-03-06 0 2026-03-07 1 Data: Rocket PizzaCase-insensitive matching with ILIKE
ILIKE ignores case. PostgreSQL's LIKE is case-sensitive; SQLite has no ILIKE (its LIKE already ignores case for English letters).
SELECT name, species FROM pets WHERE name ILIKE 'b%';Result: 3 rows
name species Biscuit dog Bruno dog Bean dog Data: Paws & Whiskers ShelterListening per month with date_trunc and to_char
date_trunc rounds a date down to the month and to_char formats it. SQLite does both with strftime.
SELECT to_char(date_trunc('month', played_on), 'YYYY-MM') AS month, COUNT(*) AS plays, SUM(minutes) AS minutes FROM plays GROUP BY 1 ORDER BY 1;Result: 4 rows
month plays minutes 2026-01 274 12626 2026-02 635 29230 2026-03 1015 48315 2026-04 483 22195 Data: StreamlyItems per category as an array, plus JSON
array_agg collects values into an array and json_build_object builds JSON. SQLite has neither (it has json_object and group_concat).
SELECT category, array_agg(name ORDER BY name) AS items, json_build_object('count', COUNT(*), 'cheapest', MIN(price)) AS summary FROM menu_items GROUP BY category ORDER BY category;Result: 4 rows
category items summary dessert ["Tiramisu"] {"count":1,"cheapest":6.5} drink ["Cola","Lemon Soda"] {"count":2,"cheapest":2.5} pizza ["BBQ Meteor","Four Cheese Orbit","Margherita","Pepperoni Rocket","Veggie Nebula"] {"count":5,"cheapest":11} side ["Caesar Salad","Garlic Knots","Wings"] {"count":3,"cheapest":5} Data: Rocket Pizza
PostgreSQL questions
Is this a real PostgreSQL?+
Yes. It's PGlite: the PostgreSQL source compiled to WebAssembly, running in your browser tab. Syntax, functions, types and error messages are PostgreSQL's own. The version is printed above.
Can I create my own tables?+
Yes. Put CREATE TABLE, INSERT and your SELECT in one run. Each run happens inside a transaction that is rolled back afterwards, so the next run starts from the sample data again.
Can I install extensions like PostGIS?+
No. The playground loads no extensions, so CREATE EXTENSION fails. Everything built into PostgreSQL itself works: JSON, arrays, window functions, recursive CTEs, generate_series.
Can I use BEGIN, COMMIT or SET?+
Transaction commands are blocked because every run is already wrapped in its own transaction. There's one connection and no server to configure, so settings, roles and LISTEN/NOTIFY don't apply.
Does PostgreSQL support RETURNING and upserts here?+
Yes. INSERT … ON CONFLICT … DO UPDATE and RETURNING work as on a server, which makes this a good place to try them without touching real data.
SQL guides
Joins, window functions, CTEs and more, with runnable examples.
SQL errors explained
What common PostgreSQL and SQLite errors mean and how to fix them.
Learn SQL daily
Five-minute lessons with instant feedback and a streak. Free to start.