|
1 | | -<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.148 2009/12/19 01:49:02 tgl Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.149 2009/12/28 19:11:51 petere Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="plpgsql"> |
4 | 4 | <title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title> |
@@ -3197,16 +3197,26 @@ RAISE unique_violation USING MESSAGE = 'Duplicate user ID: ' || user_id; |
3197 | 3197 | for this row). If a nonnull |
3198 | 3198 | value is returned then the operation proceeds with that row value. |
3199 | 3199 | Returning a row value different from the original value |
3200 | | - of <varname>NEW</> alters the row that will be inserted or updated |
3201 | | - (but has no direct effect in the <command>DELETE</> case). |
3202 | | - To alter the row to be stored, it is possible to replace single values |
3203 | | - directly in <varname>NEW</> and return the modified <varname>NEW</>, |
3204 | | - or to build a complete new record/row to return. |
| 3200 | + of <varname>NEW</> alters the row that will be inserted or |
| 3201 | + updated. Thus, if the trigger function wants the triggering |
| 3202 | + action to succeed normally without altering the row |
| 3203 | + value, <varname>NEW</varname> (or a value equal thereto) has to be |
| 3204 | + returned. To alter the row to be stored, it is possible to |
| 3205 | + replace single values directly in <varname>NEW</> and return the |
| 3206 | + modified <varname>NEW</>, or to build a complete new record/row to |
| 3207 | + return. In the case of a before-trigger |
| 3208 | + on <command>DELETE</command>, the returned value has no direct |
| 3209 | + effect, but it has to be nonnull to allow the trigger action to |
| 3210 | + proceed. Note that <varname>NEW</varname> is null |
| 3211 | + in <command>DELETE</command> triggers, so returning that is |
| 3212 | + usually not sensible. A useful idiom in <command>DELETE</command> |
| 3213 | + triggers might be to return <varname>OLD</varname>. |
3205 | 3214 | </para> |
3206 | 3215 |
|
3207 | 3216 | <para> |
3208 | | - The return value of a <literal>BEFORE</> or <literal>AFTER</> |
3209 | | - statement-level trigger or an <literal>AFTER</> row-level trigger is |
| 3217 | + The return value of a row-level trigger |
| 3218 | + fired <literal>AFTER</literal> or a statement-level trigger |
| 3219 | + fired <literal>BEFORE</> or <literal>AFTER</> is |
3210 | 3220 | always ignored; it might as well be null. However, any of these types of |
3211 | 3221 | triggers might still abort the entire operation by raising an error. |
3212 | 3222 | </para> |
|
0 commit comments