Skip to content

brainfuck

Run Brainfuck programs inside PostgreSQL using a PLV8 trusted language extension.

brainfuck · Run Brainfuck programs inside PostgreSQL using a PLV8 trusted language extension.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100966brainfuckbrainfuck4.2.0LANGApache-2.0SQL

PostgreSQL · 15, 16, 17, 18

Relationships
Requiresplv8

Usage

Sources:

brainfuck runs Brainfuck programs inside PostgreSQL through PLV8. It is useful for demonstrations and experiments, not for application logic: arbitrary programs execute JavaScript in the database backend and can consume substantial CPU.

Core Workflow

Install plv8 first, then create brainfuck:

CREATE EXTENSION plv8;
CREATE EXTENSION brainfuck;

SELECT brainfuck('++++++++[>++++++++<-]>+.', '');

The second argument supplies input consumed by the , instruction. Pass an empty string when the program needs no input.

API

brainfuck(code text, input text) RETURNS text is the extension’s only SQL function. It is declared IMMUTABLE STRICT, uses a 256-cell wrapping tape, implements the eight Brainfuck instructions, and ignores other characters in code.

Caveats

The extension requires plv8; the package registry workflow additionally uses pg_tle/dbdev, while a conventional extension installation does not. The actual SQL signature has two arguments even though an upstream README example shows one.

There is no execution limit or sandbox specific to the interpreted program. Malformed brackets fail during generated JavaScript compilation, and long-running or non-terminating programs occupy a PostgreSQL backend. Keep it out of untrusted SQL paths and use it only in controlled experiments.

Table reader