@@ -8,8 +8,8 @@ table/field names (as described below) while creating a trigger.
8
8
9
9
check_primary_key () is to used for foreign keys of a table.
10
10
11
- You are to create trigger (BEFORE INSERT OR UPDATE) using this
12
- function on a table referencing another table. You are to specify
11
+ You have to create trigger (BEFORE INSERT OR UPDATE) using this
12
+ function on a table referencing another table. You have to specify
13
13
as function arguments: triggered table column names which correspond
14
14
to foreign key, referenced table name and column names in referenced
15
15
table which correspond to primary/unique key.
@@ -18,8 +18,8 @@ one reference.
18
18
19
19
check_foreign_key () is to used for primary/unique keys of a table.
20
20
21
- You are to create trigger (BEFORE DELETE OR UPDATE) using this
22
- function on a table referenced by another table(s). You are to specify
21
+ You have to create trigger (BEFORE DELETE OR UPDATE) using this
22
+ function on a table referenced by another table(s). You have to specify
23
23
as function arguments: number of references for which function has to
24
24
performe checking, action if referencing key found ('cascade' - to delete
25
25
corresponding foreign key, 'restrict' - to abort transaction if foreign keys
@@ -42,20 +42,26 @@ refint.source).
42
42
43
43
Old internally supported time-travel (TT) used insert/delete
44
44
transaction commit times. To get the same feature using triggers
45
- you are to add to a table two columns of abstime type to store
45
+ you have to add to a table two columns of abstime type to store
46
46
date when a tuple was inserted (start_date) and changed/deleted
47
47
(stop_date):
48
48
49
49
CREATE TABLE XXX (
50
50
... ...
51
- date_on abstime default currabstime() ,
52
- date_off abstime default 'infinity'
51
+ date_on abstime,
52
+ date_off abstime
53
53
... ...
54
54
);
55
55
56
- - so, tuples being inserted with NULLs in date_on/date_off will get
57
- _current_date_ in date_on (name of start_date column in XXX) and INFINITY in
58
- date_off (name of stop_date column in XXX).
56
+ CREATE TRIGGER timetravel
57
+ BEFORE INSERT OR DELETE OR UPDATE ON tttest
58
+ FOR EACH ROW
59
+ EXECUTE PROCEDURE
60
+ timetravel (date_on, date_off);
61
+
62
+ Tuples being inserted with NULLs in date_on/date_off will get current
63
+ date in date_on (name of start_date column in XXX) and INFINITY in date_off
64
+ (name of stop_date column in XXX).
59
65
60
66
Tuples with stop_date equal INFINITY are "valid now": when trigger will
61
67
be fired for UPDATE/DELETE of a tuple with stop_date NOT equal INFINITY then
@@ -72,7 +78,7 @@ DELETE: new tuple will be inserted with stop_date setted to current date
72
78
(and with the same data in other columns as in tuple being deleted).
73
79
74
80
NOTE:
75
- 1. To get tuples "valid now" you are to add _stop_date_ = 'infinity'
81
+ 1. To get tuples "valid now" you have to add _stop_date_ = 'infinity'
76
82
to WHERE. Internally supported TT allowed to avoid this...
77
83
Fixed rewriting RULEs could help here...
78
84
As work arround you may use VIEWs...
@@ -83,22 +89,36 @@ DELETE: new tuple will be inserted with stop_date setted to current date
83
89
84
90
timetravel() is general trigger function.
85
91
86
- You are to create trigger BEFORE (!!!) UPDATE OR DELETE using this
87
- function on a time-traveled table. You are to specify two arguments: name of
88
- start_date column and name of stop_date column in triggered table.
89
-
90
- currabstime() may be used in DEFAULT for start_date column to get
91
- current date.
92
+ You have to create trigger BEFORE (!!!) INSERT OR UPDATE OR DELETE using
93
+ this function on a time-traveled table. You have to specify two arguments:
94
+ name of start_date column and name of stop_date column in triggered table.
92
95
93
96
set_timetravel() allows you turn time-travel ON/OFF for a table:
94
97
95
98
set_timetravel('XXX', 1) will turn TT ON for table XXX (and report
96
99
old status).
97
100
set_timetravel('XXX', 0) will turn TT OFF for table XXX (-"-).
98
101
99
- Turning TT OFF allows you do with a table ALL what you want.
102
+ Turning TT OFF allows you do with a table ALL what you want!
100
103
101
104
There is example in timetravel.example.
102
105
103
106
To CREATE FUNCTIONs use timetravel.sql (will be made by gmake from
104
107
timetravel.source).
108
+
109
+
110
+ 3. autoinc.c - function for implementing AUTOINCREMENT/IDENTITY feature.
111
+
112
+ You have to create BEFORE INSERT OR UPDATE trigger using function
113
+ autoinc(). You have to specify as function arguments: column name
114
+ (of int4 type) for which you want to get this feature and name of
115
+ SEQUENCE from which next value has to be fetched when NULL or 0
116
+ value is being inserted into column (, ... - you are able to specify
117
+ as many column/sequence pairs as you need).
118
+
119
+ There is example in autoinc.example.
120
+
121
+ To CREATE FUNCTION use autoinc.sql (will be made by gmake from
122
+ autoinc.source).
123
+
124
+
0 commit comments