> This page location: PostgreSQL Triggers > ALTER TRIGGER
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL ALTER TRIGGER Statement

**Info:** The `ALTER TRIGGER` statement works the same in any PostgreSQL database, so you can apply what you learn here on any Postgres instance. If you're an enterprise looking for managed Postgres built for the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers the performance, security, and Lakehouse integration you need. If you're a developer or startup who needs to ship and scale fast, [Neon](https://neon.com) is the Postgres platform built for you.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `ALTER TRIGGER` statement to rename a trigger.

## Introduction to PostgreSQL ALTER TRIGGER statement

The `ALTER TRIGGER` statement allows you to rename a trigger. The following shows the syntax of the `ALTER TRIGGER` statement:

```sql
ALTER TRIGGER trigger_name
ON table_name
RENAME TO new_trigger_name;
```

In this syntax:

- First, specify the name of the trigger you want to rename after the `ALTER TRIGGER` keywords.
- Second, provide the name of the table associated with the trigger after the `ON` keyword.
- Third, specify the new name of the trigger after the `RENAME TO` keyword.

To execute the `ALTER TRIGGER` statement, you must be the owner of the table to which the trigger belongs.

## PostgreSQL ALTER TRIGGER example

First, [create a new table](../postgresql-tutorial/postgresql-create-table) called `employees`:

```sql
DROP TABLE IF EXISTS employees;

CREATE TABLE employees(
   employee_id INT GENERATED ALWAYS AS IDENTITY,
   first_name VARCHAR(50) NOT NULL,
   last_name VARCHAR(50) NOT NULL,
   salary decimal(11,2) NOT NULL DEFAULT 0,
   PRIMARY KEY(employee_id)
);
```

Second, [create a function](../postgresql-plpgsql/postgresql-create-function) that raises an exception if the new salary is greater than the old one 100%:

```plsql
CREATE OR REPLACE FUNCTION check_salary()
  RETURNS TRIGGER
  LANGUAGE PLPGSQL
  AS
$$
BEGIN
	IF (NEW.salary - OLD.salary) / OLD.salary >= 1 THEN
		RAISE 'The salary increment cannot that high.';
	END IF;

	RETURN NEW;
END;
$$
```

Third, create a before-update trigger that executes the `check_salary()` function before updating the salary:

```sql
CREATE TRIGGER before_update_salary
  BEFORE UPDATE
  ON employees
  FOR EACH ROW
  EXECUTE PROCEDURE check_salary();
```

Fourth, [insert a new row](../postgresql-tutorial/postgresql-insert) into the `employees` table:

```sql
INSERT INTO employees(first_name, last_name, salary)
VALUES('John','Doe',100000);
```

Fifth, update the salary of the employee id 1:

```sql
UPDATE employees
SET salary = 200000
WHERE employee_id = 1;
```

The trigger was fired and issued the following error:

```
ERROR:  The salary increment cannot that high.
CONTEXT:  PL/pgSQL function check_salary() line 4 at RAISE
SQL state: P0001
```

It works as expected.

Finally, use the `ALTER TRIGGER` statement to rename the `before_update_salary` trigger to `salary_before_update`:

```sql
ALTER TRIGGER before_update_salary
ON employees
RENAME TO salary_before_update;
```

If you use psql tool, you can view all triggers associated with a table using the `\dS` command:

```
\dS employees
```

Notice that the letter `S` is uppercase.

![](https://neon.com/postgresqltutorial/PostgreSQL-ALTER-TRIGGER-example.png)

## Replacing triggers

PostgreSQL versions 14 and later support the `OR REPLACE` statement that allows you to modify the trigger definition like the function that will be executed when the trigger is fired.

The following example illustrates how to change the `check_salary` function of the `salary_before_update` trigger to `validate_salary`:

```sql
CREATE OR REPLACE TRIGGER salary_before_update
  BEFORE UPDATE
  ON employees
  FOR EACH ROW
  EXECUTE PROCEDURE validate_salary();
```

In versions prior to 14, the `OR REPLACE` statement was not supported, and to do so, you would have to use the `DROP TRIGGER` and `CREATE TRIGGER` statements. You can also wrap these statements within a [transaction](../postgresql-tutorial/postgresql-transaction) to guarantee the trigger with the old function is dropped in favor of the one with the new function.

```sql
BEGIN;

DROP TRIGGER IF EXISTS salary_before_update
ON employees;

CREATE TRIGGER salary_before_update
  BEFORE UPDATE
  ON employees
  FOR EACH ROW
  EXECUTE PROCEDURE validate_salary();

COMMIT;
```

## Summary

- Use the `ALTER TRIGGER` statement to rename a trigger.
- Use the `CREATE OR REPLACE TRIGGER` statement in new versions of PostgreSQL to replace a trigger with a new one or the pair of the `DROP TRIGGER` and `CREATE TRIGGER` statements in older versions.

---

## Related docs (PostgreSQL Triggers)

- [Introduction](https://neon.com/postgresql/triggers/introduction-postgresql-trigger)
- [CREATE TRIGGER](https://neon.com/postgresql/triggers/creating-first-trigger-postgresql)
- [DROP TRIGGER](https://neon.com/postgresql/triggers/drop-trigger)
- [AFTER INSERT Trigger](https://neon.com/postgresql/triggers/after-insert-trigger)
- [BEFORE INSERT Trigger](https://neon.com/postgresql/triggers/before-insert-trigger)
- [BEFORE UPDATE Trigger](https://neon.com/postgresql/triggers/before-update-trigger)
- [AFTER UPDATE Trigger](https://neon.com/postgresql/triggers/after-update-trigger)
- [BEFORE DELETE Trigger](https://neon.com/postgresql/triggers/before-delete-trigger)
- [AFTER DELETE Trigger](https://neon.com/postgresql/triggers/after-delete-trigger)
- [INSTEAD OF Triggers](https://neon.com/postgresql/triggers/instead-of-triggers)
- [BEFORE TRUNCATE Trigger](https://neon.com/postgresql/triggers/before-truncate-trigger)
- [Disable Triggers](https://neon.com/postgresql/triggers/managing-postgresql-trigger)
- [Enable Triggers](https://neon.com/postgresql/triggers/enable-triggers)
- [List All Triggers](https://neon.com/postgresql/triggers/how-to-list-all-triggers-in-postgresql)
- [Event Triggers](https://neon.com/postgresql/triggers/event-trigger)
- [Conditional Triggers](https://neon.com/postgresql/triggers/trigger-when-condition)
