![]() For INSERT and UPDATE operations, the return value should be NEW, which the trigger function may modify to support INSERT RETURNING and UPDATE RETURNING (this will also affect the row value passed to any subsequent triggers, or passed to a special EXCLUDED alias reference within an INSERT statement with an ON CONFLICT DO UPDATE clause). Otherwise a nonnull value should be returned, to signal that the trigger performed the requested operation. INSTEAD OF triggers (which are always row-level triggers, and may only be used on views) can return null to signal that they did not perform any updates, and that the rest of the operation for this row should be skipped (i.e., subsequent triggers are not fired, and the row is not counted in the rows-affected status for the surrounding INSERT/ UPDATE/ DELETE). The usual idiom in DELETE triggers is to return OLD. ![]() Note that NEW is null in DELETE triggers, so returning that is usually not sensible. ![]() In the case of a before-trigger on DELETE, the returned value has no direct effect, but it has to be nonnull to allow the trigger action to proceed. To alter the row to be stored, it is possible to replace single values directly in NEW and return the modified NEW, or to build a complete new record/row to return. Thus, if the trigger function wants the triggering action to succeed normally without altering the row value, NEW (or a value equal thereto) has to be returned. Returning a row value different from the original value of NEW alters the row that will be inserted or updated. If a nonnull value is returned then the operation proceeds with that row value. Row-level triggers fired BEFORE can return null to signal the trigger manager to skip the rest of the operation for this row (i.e., subsequent triggers are not fired, and the INSERT/ UPDATE/ DELETE does not occur for this row). Invalid indexes (less than 0 or greater than or equal to tg_nargs) result in a null value.Ī trigger function must return either NULL or a record/row value having exactly the structure of the table the trigger was fired for. TG_ARGV text #Īrguments from the CREATE TRIGGER statement. Number of arguments given to the trigger function in the CREATE TRIGGER statement. Schema of the table that caused the trigger invocation. Table that caused the trigger invocation. This is now deprecated, and could disappear in a future release. Object ID of the table that caused the trigger invocation. ![]() Operation for which the trigger was fired: INSERT, UPDATE, DELETE, or TRUNCATE. ROW or STATEMENT, depending on the trigger's definition. TG_WHEN text #īEFORE, AFTER, or INSTEAD OF, depending on the trigger's definition. This variable is null in statement-level triggers and for INSERT operations. Old database row for UPDATE/ DELETE operations in row-level triggers. This variable is null in statement-level triggers and for DELETE operations. New database row for INSERT/ UPDATE operations in row-level triggers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |