refint
functions for implementing referential integrity (obsolete)
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
refint | 1.0 | FUNC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4880 | refint | No | Yes | No | Yes | No | No | - |
| Related | pg_idkit pgx_ulid pg_uuidv7 permuteseq pg_hashids sequential_uuids topn quantile |
|---|
Version
| PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|
| 1.0 | 1.0 | 1.0 | 1.0 | 1.0 |
Install
Note: This is a built-in contrib extension of PostgreSQL
CREATE EXTENSION refint;
Usage
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');
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.