The RENAME keyword allows you to change the name of a variable, record, or row. This is helpful if the NEW or OLD keyword is referenced by another name inside of a trigger procedure. For more details on triggers, refer to the Triggers section.
If you need to change the name of a variable, record, or row, use the rename syntax:
RENAME oldname TO newname;
Remember, rename is defined in the declarations section of a block. Here are two examples:
DECLARE RENAME isbn TO book_id; BEGIN ... DECLARE RENAME old TO author_row; BEGIN ...
This function uses the rename keyword to rename a new row to be replaced into the book table. By renaming new to data, it can be called in the body of the function as data.
CREATE FUNCTION rename_new () RETURNS opaque AS ' DECLARE -- gives the new trigger variable name -- another name, data rename new to data; BEGIN -- returns the new row into the book table return data; END; ' LANGUAGE 'plpgsql';
For more information on trigger variables, refer to the trigger section.
This trigger invokes that function when an update occurs on the book table:
CREATE TRIGGER rename_new BEFORE UPDATE on book FOR EACH row EXECUTE PROCEDURE rename_new();