Skip to content
T

Tetris SQL

Using SQL's Turing Completeness to Build Tetris

by nuno-fariaFree

#656in Entertainment
0In stores

Description

Tetris-SQL is a playable implementation of Tetris written as a single SQL query for PostgreSQL. It relies on recursive common table expressi…

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

T

Tetro Tui

Terminal-based but modern tetromino-stacking game

Entertainment
Launch
T

Tetris

A terminal interface for Tetris

Entertainment
Launch
L

Lost at SQL

SQL learning game

Developer Tools
Launch
B

Blockrain.js

Embed & play the classic game on your site. Simple as that

Entertainment
Launch
T

Tetris Game

A Tetris Game with AI

AI
Launch
C

Custom Tetris

Play the classic Tetris game the way you like it

Entertainment
Launch

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

Developer Stuff

Badges