Pure SQL QR Code Generator for PostgreSQL: An AI-Assisted Experiment

Database

Discover a pure SQL QR code generator for PostgreSQL, created with AI assistance. Learn about its experimental nature, usage, and a humorous reflection on modern development tools.

Waking up early on a Saturday, I decided to leverage my extra time and ChatGPT Pro subscription to create a QR code generator for PostgreSQL, implemented as a single, pure SQL statement. This solution requires no external libraries or PostgreSQL extension installations.

While this project was primarily for fun and learning, and likely not optimal for production environments, optimizing its SQL performance presents an interesting challenge. My tests showed PostgreSQL 17 executing it significantly faster than version 16, though I haven't yet compared their execution plans.

The pqr.sql example demonstrates simple usage:

$ psql -qf pqr.sql -v payload='Hello, World!'

For enhanced safety, there's also a pqrsafe.sql version that raises an error if the payload exceeds the maximum length encodable in a QR code, unlike the basic version which would simply generate an unreadable QR code. Here's an example:

$ psql -qf pqrsafe.sql -v payload='Hello, World!!!'
Version 1-M (ECC M) cannot encode byte payloads that long. Got 15 characters (15 bytes).

Fun fact: Approximately two decades ago, I dedicated an entire Sunday to manually developing a critical "production fish generator" utility for large-scale Oracle databases. Today, I completed the entire QR code generation project in just about an hour, primarily by interacting with OpenAI Codex.

I feel like an 11x engineer now!