Database Reference
In-Depth Information
(new.warehouse_id, current_timestamp);
RETURN NEW;
END;
$first_trigger$ LANGUAGE plpgsql;
Now, we will deine the trigger and bind it to the associated table warehouse_tbl
as follows:
warehouse_db=# CREATE TRIGGER audit_trigger
AFTER INSERT ON warehouse_tbl
FOR EACH ROW
EXECUTE PROCEDURE warehouse_audit_func();
Let's insert a row in the warehouse_tbl table and verify the changes in the
warehouse_audit table:
warehouse_db=# INSERT INTO warehouse_tbl
(warehouse_id, warehouse_name, year_created, street_address,
city, state, zip)
VALUES
(3, 'West point', 2013, 'Down Town', 'New London', 'CT', 4321);
We can see that the changes are logged in the warehouse_audit table after INSERT
on the warehouse_tbl table. We will use a SELECT command to check whether the
record was inserted in the warehouse_audit table.
The result can be seen using the following statement:
warehouse_db=# SELECT * FROM warehouse_audit;
wlog_id | insertion_time
---------+-------------------------------
3 | 2014-09-01 03:09:38.791989+05
(1 row)
Now to check whether the record is inserted in the warehouse_tbl table, use the
following statement:
warehouse_db=# SELECT warehouse_id, warehouse_name, state FROM
warehouse_tbl;
warehouse_id | warehouse_name | state
--------------+----------------+-------
1 | Mark Corp | CT
2 | Bill & Co | CT
3 | West point | CT
(3 rows)
 
Search WWH ::




Custom Search