pg_luhn

A pure SQL implementation of the Luhn Algorithm

Example

SELECT luhn_verify(5432);
 luhn_verify
-------------
 f
(1 row)

SELECT luhn_verify(5439);
 luhn_verify
-------------
 t
(1 row)


postgres=# SELECT luhn_generate(543);
 luhn_generate
---------------
           5439

Install

make
make install

Once the extension is installed on the server, you can create it inside the database.

CREATE EXTENSION pg_luhn;

Credits

This extension is based on the work of Craig Ringer published on the PostgreSQL Wiki