refint

refint

refint : functions for implementing referential integrity (obsolete)

Overview

ID Extension Package Version Category License Language
4880
refint
refint
1.0
FUNC
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
See Also
pg_idkit
pgx_ulid
pg_uuidv7
permuteseq
pg_hashids
sequential_uuids
topn
quantile

Packages

PG18 PG17 PG16 PG15 PG14
1.0
1.0
1.0
1.0
1.0

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

Install

Create this extension with:

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

Function Description
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 updated on