Skip to Main Content
Practical PostgreSQL
book

Practical PostgreSQL

by Joshua D. Drake, John C. Worsley
January 2002
Intermediate to advanced content levelIntermediate to advanced
640 pages
16h 39m
English
O'Reilly Media, Inc.
Content preview from Practical PostgreSQL

Create Trigger

Creates a new trigger.

Synopsis

CREATE TRIGGER name { BEFORE | AFTER } { event [ OR event ... ] }
       ON table FOR EACH { ROW | STATEMENT }
       EXECUTE PROCEDURE function ( arguments )

Parameters

name

The name of the new trigger.

table

The name of the table with which the trigger will be associated.

event

The event with which you wish to associate the trigger, that causes the trigger to fire. Valid events are: INSERT, DELETE, and UPDATE. A trigger may be associated with more than one event.

function

The name of the function you wish to link to the new trigger. When the trigger fires, the function is invoked. The function must return a variable of type opaque; the opaque type is used only by internal functions and such functions cannot be invoked directly from SQL.

arguments

The arguments to pass to the function when the trigger is called.

Results

CREATE

The message returned when a trigger is successfully created.

Description

Use the CREATE TRIGGER command to add a trigger to a database. When a trigger is added to the database, it is associated with the table specified in the ON clause. When the specified event “fires” the trigger, the function you specified will be executed.

Note

Description

A trigger may only be created on a table by the table’s owner, or by a superuser.

When you create a trigger, you must specify whether it is to be fired before or after the event is attempted (or completed). If the trigger ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PostgreSQL: Up and Running, 2nd Edition

PostgreSQL: Up and Running, 2nd Edition

Regina O. Obe, Leo S. Hsu
Learning PostgreSQL 11 - Third Edition

Learning PostgreSQL 11 - Third Edition

Christopher Travers, Andrey Volkov
Learn PostgreSQL

Learn PostgreSQL

Luca Ferrari, Enrico Pirozzi
PostgreSQL 13 Cookbook

PostgreSQL 13 Cookbook

Vallarapu Naga Avinash Kumar

Publisher Resources

ISBN: 9781449309770Supplemental ContentErrata Page