play
write sql, run it right here, on a real postgres 18.6 compiled to webassembly. nothing leaves your machine.
a brand new database with nothing in it. the default when a block doesn't say db=.
no tables yet. CREATE TABLE something.
how this works, honestly
this is the real postgres 18.6 source, compiled to webassembly by the PGlite project (0.5.12), running in a web worker in this tab. the first run downloads about 6.0 MB, once. then it builds the dataset you picked from plain sql, which takes a second or so, and keeps a snapshot of it in memory.
every run starts from a fresh copy of that snapshot, unless “keep changes between runs” is on: then your tables and rows stay until you reset. the book's code blocks always start fresh, so they print exactly what the book shows. the book checks every one of them against this same engine.
it is postgres, but a postgres with a few things missing:
- one connection. there's no second session, so nothing here can show two transactions racing or a lock wait. the book shows those with recordings from a real server.
- no background processes: no autovacuum, no background writer or checkpointer, no parallel workers.
- text sorts in byte order by default (the C collation; the ICU root collation "unicode" is there too, language-specific ones aren't), and the clock and random() are your machine's.
- no files on the server and no COPY ... FROM STDIN. the extensions are the six for looking inside: pageinspect, pg_buffercache, pg_visibility, pg_walinspect, amcheck, pg_freespacemap, pg_trgm, btree_gist, ltree.
- a running query can't be cancelled from inside, so after 30 seconds the whole engine is stopped and started again. kept changes are lost when that happens.
the glue is small and lives in public/sql and the datasets in datasets/, all plain sql.