The PL/pgSQL functions have several special variables that are automatically created in the top-level block. For example, if the function returns a trigger, then several variables, such as NEW, OLD, and TG_OP, are created.
In addition to the trigger special values, there is a Boolean variable called FOUND. This is often used in combination with DML and PERFORM statements, in order to conduct sanity checks. The value of the FOUND variable is affected by the SELECT, INSERT, UPDATE, DELETE, and PERFORM statements. These statements set FOUND to true if at least one row is selected, inserted, updated, or deleted.
The PERFORM statement is similar to the SELECT statement, but it discards the result of the query. Finally, the EXECUTE statement does not change the value of the FOUND variable. The following examples show how the FOUND variable is affected by...