1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-14 02:22:38 +03:00
Files
config
contrib
adddepend
array
btree_gist
chkpass
cube
dbase
dblink
dbmirror
dbsize
earthdistance
findoidjoins
fulltextindex
fuzzystrmatch
intagg
intarray
ipc_check
isbn_issn
lo
ltree
mSQL-interface
mac
miscutil
mysql
noupdate
oid2name
oracle
pg_autovacuum
pg_buffercache
pg_dumplo
pg_trgm
pg_upgrade
pgbench
pgcrypto
pgstattuple
reindexdb
rtree_gist
seg
spi
preprocessor
README.MAX
example.sql
step1.c
step2.pl
Makefile
README.spi
README.timetravel
autoinc.c
autoinc.example
autoinc.sql.in
insert_username.c
insert_username.example
insert_username.sql.in
moddatetime.c
moddatetime.example
moddatetime.sql.in
refint.c
refint.example
refint.sql.in
timetravel.c
timetravel.example
timetravel.sql.in
start-scripts
string
tablefunc
tips
tools
tsearch
tsearch2
userlock
vacuumlo
xml
xml2
Makefile
README
contrib-global.mk
doc
src
COPYRIGHT
GNUmakefile.in
Makefile
README
README.CVS
aclocal.m4
configure
configure.in
postgres/contrib/spi/preprocessor/README.MAX
Bruce Momjian d489fdfc7f I send you a attach of my modified refint.c that
works with a new policy  in cascade mode .

Please Read README.MAX .
I do not know if you are the author of refint.c ,
but if not please tell me who is .


Thank you ( excuse me for my bad english) .
Massimo Lambertini massimo.lambertini@everex.it
1999-05-10 15:12:29 +00:00

77 lines
2.7 KiB
Plaintext

Here are general trigger functions provided as workable examples
of using SPI and triggers. "General" means that functions may be
used for defining triggers for any tables but you have to specify
table/field names (as described below) while creating a trigger.
1. refint.c - functions for implementing referential integrity.
check_primary_key () is to used for foreign keys of a table.
You are to create trigger (BEFORE INSERT OR UPDATE) using this
function on a table referencing another table. You are to specify
as function arguments: triggered table column names which correspond
to foreign key, referenced table name and column names in referenced
table which correspond to primary/unique key.
You may create as many triggers as you need - one trigger for
one reference.
check_foreign_key () is to used for primary/unique keys of a table.
You are to create trigger (BEFORE DELETE OR UPDATE) using this
function on a table referenced by another table(s). You are to specify
as function arguments: number of references for which function has to
performe checking, action if referencing key found ('cascade' - to delete
corresponding foreign key, 'restrict' - to abort transaction if foreign keys
exist, 'setnull' - to set foreign key referencing primary/unique key
being deleted to null), triggered table column names which correspond
to primary/unique key, referencing table name and column names corresponding
to foreign key (, ... - as many referencing tables/keys as specified
by first argument).
Note, that NOT NULL constraint and unique index have to be defined by
youself.
There are examples in refint.example and regression tests
(sql/triggers.sql).
To CREATE FUNCTIONs use refint.sql (will be made by gmake from
refint.source).
# Excuse me for my bad english. Massimo Lambertini
#
#
# New check foreign key
#
I think that cascade mode is to be considered like that the operation over
main table is to be made also in referenced table .
When i Delete , i must delete from referenced table ,
but when i update , i update referenced table and not delete like unmodified refint.c .
I made a patch that when i update it check the type of modified key ( if is a text , char() i
added '') and then create a update query that do the right think .
For my point of view that policy is helpfull because i do not have in referenced table
loss of information .
In preprocessor subdir i have placed a little utility that from a SQL92 table definition,
it create all trigger for foreign key .
the schema that i use to analyze the problem is this
create table
A
( key int4 not null primary key ,...) ;
create table
REFERENCED_B
( key int 4 , ... ,
foreign key ( key ) references A --
);