nanoid-postgres icon indicating copy to clipboard operation
nanoid-postgres copied to clipboard

Nanoid implementation in PostgreSQL PL/pgSQL

nanoid-postgres

Nanoid implementation in PostgreSQL PL/pgSQL

Requirements

  • Postgres with pgcrypto

Usage

Run the SQL file, or include the function in your database migrations

Use as the default value for your id columns!

CREATE TABLE users (
  "id" char(21) NOT NULL DEFAULT nanoid(),
  ...
)

Todo

  • Function that takes a custom alphabet