To rename a trigger, the user must be the owner of the table on which the trigger is defined.
Synopsis
Parameters
Parameter
Description
IF EXISTS
Rename the trigger only if the table and trigger exist. If the table or trigger does not exist, the statement succeeds without renaming a trigger.
trigger_name
The current name of the trigger.
table_name
The name of the table associated with the trigger.
trigger_new_name
The new name of the trigger.
ALTER TRIGGER ... IF EXISTS is a CockroachDB extension of the PostgreSQL syntax, which does not accept IF EXISTS for ALTER TRIGGER.
Renaming a trigger to its current name succeeds without changes. Renaming a trigger to a name that is already used by another trigger on the same table returns a duplicate-object error.
Examples
Setup
To follow along, run cockroach demo to start a temporary, in-memory cluster with the movr sample dataset preloaded:
$ cockroach demo
Rename a trigger
Create a sample trigger function:
CREATE FUNCTION update_timestamp()RETURNS TRIGGER AS $$BEGIN RAISE NOTICE 'Current timestamp: %', now(); RETURN NEW;END;$$ LANGUAGE PLpgSQL;
Create a sample trigger:
CREATE TRIGGER log_update_timestampAFTER UPDATE ON usersFOR EACH ROWEXECUTE FUNCTION update_timestamp();
Rename the trigger:
ALTER TRIGGER log_update_timestamp ON users RENAME TO log_updates;