pqr.sql: Generate QR Codes with Pure SQL in PostgreSQL 2025-10-11 As my cat woke me up way too early for a Saturday morning, I decided to put all this extra time (and my ChatGPT Pro subscription) into good use and generated a QR-code generator for PostgreSQL, written as a single pure SQL statement. No external libraries or Postgres extension installation needed! I did this purely for fun and learning, I don’t think this is going to be the best way for generating QR codes in production. But optimizing this SQL to run faster should be a fun learning exercise. PostgreSQL 17 ran it much faster than 16 in my lab, haven’t gotten to compare the execution plans yet. The pqr.sql example usage is simple: $ psql -qf pqr.sql -v payload='Hello, World!' There’s also a bit more complex version pqrsafe.sql that raises an error if you’re trying to encode a too long payload into the QR code (the basic version would just generate a QR code that doesn’t “read”). $ 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: about 20 years ago, I spent my entire Sunday manually writing an important production fish generator utility for large-scale Oracle databases. Today I got all the QR code work done with just an hour of talking to OpenAI Codex. I am an 11x engineer now!
First seen: 2026-01-14 23:11
Last seen: 2026-01-15 01:13