On Thu, 2008-09-18 at 15:04 -0400, Tom Lane wrote: > This does seem like a bit of a gotcha for someone who writes RETURN NEW > instead of RETURN OLD or vice versa, but I'm not sure how much we can do > about that. Lots of people like to write triggers that fire on multiple > event types, so we couldn't throw a syntax error for such a reference. > A runtime error for a use of the variable might be possible, but a quick > look at the code doesn't make it look easy. > Here's a doc patch that may clear up some of the confusion. Regards, Jeff Davis
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 9b2e2e9..bdc16db 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -3036,7 +3036,8 @@ RAISE unique_violation USING MESSAGE = 'Duplicate user ID: ' || user_id; <para> Data type <type>RECORD</type>; variable holding the new database row for <command>INSERT</>/<command>UPDATE</> operations in row-level - triggers. This variable is <symbol>NULL</symbol> in statement-level triggers. + triggers. This variable is <symbol>NULL</symbol> in statement-level triggers + and for <command>DELETE</command> operations. </para> </listitem> </varlistentry> @@ -3047,7 +3048,8 @@ RAISE unique_violation USING MESSAGE = 'Duplicate user ID: ' || user_id; <para> Data type <type>RECORD</type>; variable holding the old database row for <command>UPDATE</>/<command>DELETE</> operations in row-level - triggers. This variable is <symbol>NULL</symbol> in statement-level triggers. + triggers. This variable is <symbol>NULL</symbol> in statement-level triggers + and for <command>INSERT</command> operations. </para> </listitem> </varlistentry>