isn

isn : data types for international product numbering standards

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3930
isn
isn
1.2
TYPE
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-dt-
No
Yes
No
Yes
no
yes
Relationships
See Also
prefix
semver
unit
pgpdf
pglite_fusion
md5hash
asn1oid
roaringbitmap

Packages

PG18PG17PG16PG15PG14
1.2
1.2
1.2
1.2
1.2

This is a built-in contrib extension ship with the PostgreSQL kernel

Install

Create this extension with:

CREATE EXTENSION isn;

Usage

isn: ISBN, ISSN, EAN, UPC product number types

The isn extension provides data types for international product numbering standards with validation and check-digit verification.

CREATE EXTENSION isn;

Data Types

TypeDescription
EAN13European Article Numbers (always 13-digit)
ISBN13International Standard Book Numbers (13-digit)
ISMN13International Standard Music Numbers (13-digit)
ISSN13International Standard Serial Numbers (13-digit)
ISBNBook numbers (10-digit short format when possible)
ISMNMusic numbers (10-digit short format when possible)
ISSNSerial numbers (10-digit short format when possible)
UPCUniversal Product Codes

Examples

SELECT isbn('978-0-393-04002-9');
SELECT isbn13('0901690546');
SELECT issn('1436-4522');

-- Create table with ISBN column
CREATE TABLE books (id isbn);
INSERT INTO books VALUES ('9780393040029');

-- Auto-calculate check digit with ?
INSERT INTO books VALUES ('220500896?');

-- Type casting
SELECT ean13('0901690546'::isbn);

Weak Mode

Enable weak mode to accept invalid check digits (useful for OCR/data cleanup):

SET isn.weak TO true;
INSERT INTO books VALUES ('978-0-11-000533-4');
SET isn.weak TO false;

-- Find invalid entries
SELECT id FROM books WHERE NOT is_valid(id);

-- Fix invalid entries
UPDATE books SET id = make_valid(id) WHERE id = '2-205-00876-X!';

Functions

FunctionDescription
is_valid(isn)Check if value has valid check digit
make_valid(isn)Clear the invalid-check-digit flag
isn_weak()Return current weak mode status
isn_weak(boolean)Set weak mode

Operators and Indexing

Standard comparison operators (=, <, >, <=, >=, <>) with B-tree and hash index support.

Last updated on