refint

functions for implementing referential integrity (obsolete)

Overview

PackageVersionCategoryLicenseLanguage
refint1.0FUNCPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4880refintNoYesNoYesNoNo-
Relatedpg_idkit pgx_ulid pg_uuidv7 permuteseq pg_hashids sequential_uuids topn quantile

Version

PG18PG17PG16PG15PG14
1.01.01.01.01.0

Install

Note: This is a built-in contrib extension of PostgreSQL

CREATE EXTENSION refint;

Usage

refint: referential integrity trigger functions

Provides trigger functions for implementing referential integrity checks (largely superseded by built-in foreign key constraints).

CREATE EXTENSION refint;

Trigger Functions

FunctionDescription
check_primary_key()Check referencing table – ensures referenced row exists
check_foreign_key()Check referenced table – handles cascading actions on delete/update

check_primary_key

Trigger on the referencing table (AFTER INSERT OR UPDATE). Parameters: referencing column name(s), referenced table name, referenced column name(s).

CREATE TRIGGER check_fk
  AFTER INSERT OR UPDATE ON orders
  FOR EACH ROW
  EXECUTE FUNCTION check_primary_key('customer_id', 'customers', 'id');

check_foreign_key

Trigger on the referenced table (AFTER DELETE OR UPDATE). Parameters: number of referencing tables, action (cascade, restrict, or setnull), primary key column(s), then referencing table and column pairs.

CREATE TRIGGER check_ref
  AFTER DELETE OR UPDATE ON customers
  FOR EACH ROW
  EXECUTE FUNCTION check_foreign_key(1, 'cascade', 'id', 'orders', 'customer_id');

Last Modified 2026-03-12: add pg extension catalog (95749bf)