Description
Tetris-SQL is a playable implementation of Tetris written as a single SQL query for PostgreSQL. It relies on recursive common table expressions, which made SQL Turing complete, to run the game loop inside the database, while a small Python script turns your key presses into SQL commands. You run the input script in one terminal and the Tetris query in another, then switch back to the input terminal to play. It needs a PostgreSQL server (tested on versions 10 to 18), Python 3 with psycopg2 and a terminal, and the README includes Docker steps for setting everything up. The project is a technical demonstration rather than a game product, and its implementation was presented at PGConf.EU 2025.…
Highlights
- Full Tetris game written in one SQL query
- Uses recursive CTEs for the game loop
- Python input script that sends key presses as SQL
- Tested on PostgreSQL 10 to 18
- Docker setup instructions included
Ratings & Reviews
No ratings yet
Be the first to rate Tetris SQL.
People also visit
Tetris SQL FAQ
How can Tetris run in SQL?
Recursive common table expressions, added in SQL:1999, make SQL Turing complete, so the game loop can be expressed as a recursive query.
What do I need to play?
A PostgreSQL server (tested with versions 10 to 18), Python 3 with psycopg2, and a terminal such as Windows Terminal, GNOME Terminal or iTerm2.
How do I start the game?
Run input.py in one terminal, run the Tetris query in another, then switch to the input terminal to play.
Why is there a delay at the start?
Postgres spends time JIT-compiling the plan. You can disable that with SET jit = off.
Where can I learn how it works?
The README explains the implementation, and slides from the PGConf.EU 2025 talk are linked.
What are the best Tetris SQL alternatives?
Popular alternatives to Tetris SQL include Tetro Tui, Tetris and Blockrain.js. See all Tetris SQL alternatives




