head	1.8;
access;
symbols
	REL7_0_PATCHES:1.6.0.4
	REL7_0:1.6
	REL6_5_PATCHES:1.6.0.2
	REL6_5:1.6
	REL6_4:1.4.0.2
	release-6-3:1.4;
locks; strict;
comment	@# @;


1.8
date	2000.06.19.14.07.22;	author momjian;	state dead;
branches;
next	1.7;

1.7
date	2000.06.19.13.54.15;	author momjian;	state Exp;
branches;
next	1.6;

1.6
date	99.05.10.15.12.27;	author momjian;	state Exp;
branches;
next	1.5;

1.5
date	98.12.14.05.13.39;	author momjian;	state Exp;
branches;
next	1.4;

1.4
date	97.10.17.09.55.29;	author vadim;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	97.10.02.18.01.52;	author vadim;	state Exp;
branches;
next	1.2;

1.2
date	97.09.24.08.17.12;	author vadim;	state Exp;
branches;
next	1.1;

1.1
date	97.09.12.02.41.13;	author vadim;	state Exp;
branches;
next	;

1.4.2.1
date	98.12.14.05.14.09;	author momjian;	state Exp;
branches;
next	;


desc
@@


1.8
log
@Remove old README files.
@
text
@@


1.7
log
@Update to /contrib from Karel.
@
text
@@


1.6
log
@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
@
text
@a0 104

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).


2. timetravel.c - functions for implementing time travel feature.

   Old internally supported time-travel (TT) used insert/delete
transaction commit times. To get the same feature using triggers
you are to add to a table two columns of abstime type to store
date when a tuple was inserted (start_date) and changed/deleted 
(stop_date):

CREATE TABLE XXX (
	...		...
	date_on		abstime default currabstime(),
	date_off	abstime default 'infinity'
	...		...
);

- so, tuples being inserted with NULLs in date_on/date_off will get
_current_date_ in date_on (name of start_date column in XXX) and INFINITY in
date_off (name of stop_date column in XXX).

   Tuples with stop_date equal INFINITY are "valid now": when trigger will
be fired for UPDATE/DELETE of a tuple with stop_date NOT equal INFINITY then
this tuple will not be changed/deleted!

   If stop_date equal INFINITY then on

UPDATE: only stop_date in tuple being updated will be changed to current
date and new tuple with new data (coming from SET ... in UPDATE) will be
inserted. Start_date in this new tuple will be setted to current date and
stop_date - to INFINITY.

DELETE: new tuple will be inserted with stop_date setted to current date
(and with the same data in other columns as in tuple being deleted).

   NOTE:
1. To get tuples "valid now" you are to add _stop_date_ = 'infinity'
   to WHERE. Internally supported TT allowed to avoid this...
   Fixed rewriting RULEs could help here...
   As work arround you may use VIEWs...
2. You can't change start/stop date columns with UPDATE! 
   Use set_timetravel (below) if you need in this.

   FUNCTIONs:

timetravel() is general trigger function.

   You are to create trigger BEFORE (!!!) UPDATE OR DELETE using this
function on a time-traveled table. You are to specify two arguments: name of
start_date column and name of stop_date column in triggered table.

currabstime() may be used in DEFAULT for start_date column to get
current date.

set_timetravel() allows you turn time-travel ON/OFF for a table:

   set_timetravel('XXX', 1) will turn TT ON for table XXX (and report
old status).
   set_timetravel('XXX', 0) will turn TT OFF for table XXX (-"-).

Turning TT OFF allows you do with a table ALL what you want.

   There is example in timetravel.example.

   To CREATE FUNCTIONs use timetravel.sql (will be made by gmake from
timetravel.source).
@


1.5
log
@OK, here is a diff for the README file in /usr/src/pgsql/contrib/spi/.
For the 6.5 tree.

Have a great night.
Terry
@
text
@d11 2
a12 2
   You have to create trigger (BEFORE INSERT OR UPDATE) using this 
function on a table referencing another table. You have to specify
d21 2
a22 2
   You have to create trigger (BEFORE DELETE OR UPDATE) using this
function on a table referenced by another table(s). You have to specify
d45 1
a45 1
you have to add to a table two columns of abstime type to store
d51 2
a52 2
	date_on		abstime,
	date_off	abstime
d56 3
a58 9
CREATE TRIGGER timetravel
        BEFORE INSERT OR DELETE OR UPDATE ON tttest
        FOR EACH ROW
        EXECUTE PROCEDURE
        timetravel (date_on, date_off);

   Tuples being inserted with NULLs in date_on/date_off will get current
date in date_on (name of start_date column in XXX) and INFINITY in date_off
(name of stop_date column in XXX).
d75 1
a75 1
1. To get tuples "valid now" you have to add _stop_date_ = 'infinity'
d86 6
a91 3
   You have to create trigger BEFORE (!!!) INSERT OR UPDATE OR DELETE using
this function on a time-traveled table. You have to specify two arguments:
name of start_date column and name of stop_date column in triggered table.
d99 1
a99 1
Turning TT OFF allows you do with a table ALL what you want!
a104 42


3. autoinc.c - function for implementing AUTOINCREMENT/IDENTITY feature.

   You have to create BEFORE INSERT OR UPDATE trigger using function
autoinc(). You have to specify as function arguments: column name
(of int4 type) for which you want to get this feature and name of
SEQUENCE from which next value has to be fetched when NULL or 0
value is being inserted into column (, ... - you are able to specify
as many column/sequence pairs as you need).

   There is example in autoinc.example.

   To CREATE FUNCTION use autoinc.sql (will be made by gmake from
autoinc.source).


4. insert_username.c - function for inserting user names.

   You have to create BEFORE INSERT OR UPDATE trigger using the function
insert_username(). You have to specify as a function argument: the column
name (of text type) in which user names will be inserted.  Note that user
names will be inserted irregardless of the initial value of the field, so
that users cannot bypass this functionality by simply defining the field to
be NOT NULL.

   There is an example in insert_username.example.

   To CREATE FUNCTION use insert_username.sql (will be made by gmake from
insert_username.source).


5. moddatetime.c - function for maintaining a modification datetime stamp.

   You have to create a BEFORE UPDATE trigger using the function moddatetime().
One argument must be given, that is the name of the field that is of type 
datetime that is to be used as the modification time stamp.

   There is an example in moddatetime.example.
	
   To CREATE FUNCTION use moddatetime.sql ( will be made by gmake from 
moddatetime.source).
@


1.4
log
@Trigger function for inserting user names.
Install compiled functions into $(LIBDIR)/contrib.
(Thanks to Brook Milligan <brook@@trillium.NMSU.Edu>)
@
text
@d138 12
@


1.4.2.1
log
@OK, here is a diff for the README file in /usr/src/pgsql/contrib/spi/.
For the 6.5 tree.

Have a great night.
Terry
@
text
@a137 12


5. moddatetime.c - function for maintaining a modification datetime stamp.

   You have to create a BEFORE UPDATE trigger using the function moddatetime().
One argument must be given, that is the name of the field that is of type 
datetime that is to be used as the modification time stamp.

   There is an example in moddatetime.example.
	
   To CREATE FUNCTION use moddatetime.sql ( will be made by gmake from 
moddatetime.source).
@


1.3
log
@General function for SERIAL/IDENTITY/AUTOINCREMENT feature.
Handle INSERT event in timetravel().
@
text
@d125 13
@


1.2
log
@General trigger functions for time-travel
@
text
@d11 2
a12 2
   You are to create trigger (BEFORE INSERT OR UPDATE) using this 
function on a table referencing another table. You are to specify
d21 2
a22 2
   You are to create trigger (BEFORE DELETE OR UPDATE) using this
function on a table referenced by another table(s). You are to specify
d45 1
a45 1
you are to add to a table two columns of abstime type to store
d51 2
a52 2
	date_on		abstime default currabstime(),
	date_off	abstime default 'infinity'
d56 9
a64 3
- so, tuples being inserted with NULLs in date_on/date_off will get
_current_date_ in date_on (name of start_date column in XXX) and INFINITY in
date_off (name of stop_date column in XXX).
d81 1
a81 1
1. To get tuples "valid now" you are to add _stop_date_ = 'infinity'
d92 3
a94 6
   You are to create trigger BEFORE (!!!) UPDATE OR DELETE using this
function on a time-traveled table. You are to specify two arguments: name of
start_date column and name of stop_date column in triggered table.

currabstime() may be used in DEFAULT for start_date column to get
current date.
d102 1
a102 1
Turning TT OFF allows you do with a table ALL what you want.
d108 17
@


1.1
log
@README for refint.c and example of using.
@
text
@d31 2
a32 2
   Note, that NOT NULL constraint and unique index have to be defined
by youself.
d34 1
a34 1
   There are examples in refint.example and regression tests 
d37 2
d40 65
@
