Database Reference
In-Depth Information
Check the table contents as follows:
warehouse_db=# SELECT * FROM tab_perl;
emp_id | emp_name | emp_city
--------+----------+----------
1 | Adam | Chicago
2 | John | Miami
3 | Roger | Boston
(3 rows)
This time the operation was successful and the table is updated.
Creating triggers in PL/Tcl
We will reuse the previous example to write trigger procedures in PL/Tcl. Let's go
through the syntax for some of the trigger variables and give some information:
•
$TG_name
: This is the name of the trigger
•
$TG_table_name
: This is the name of the table to which the trigger is
associated
•
$TG_op
: This is a string that can have the value
INSERT
,
UPDATE
,
DELETE
,
or
TRUNCATE
•
$NEW
: This is indexed by the column name; it's an associative array that
contains new row values for
INSERT
,
UPDATE
, or empty in the case of
DELETE
•
$OLD
: This is indexed by the column name; it's an associative array that
contains old row values for
UPDATE
or
DELETE
or empty in the case of
INSERT
Let's start with creating a table that contains a few rows in the following manner:
warehouse_db=# CREATE TABLE tab_tcl
(
emp_id INT NOT NULL,
emp_name VARCHAR(10),
emp_city VARCHAR(10)
);
Insert rows in the
tab_tcl
table using the following statement:
warehouse_db=# INSERT INTO tab_tcl VALUES (1, 'Adam', 'Chicago');
warehouse_db=# INSERT INTO tab_tcl VALUES (2, 'John', 'Miami');