Assigning NULL to a record variable - Mailing list pgsql-hackers

From Kevin Grittner
Subject Assigning NULL to a record variable
Date
Msg-id 20120920210519.241290@gmx.com
Whole thread Raw
Responses Re: Assigning NULL to a record variable  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Related to bug #6123, Wisconsin Courts are now using triggers with
the workaround to be safe with the patch put forward by Tom, even
though they are still running with the earlier patch proposal by me
(which tolerates an UPDATE or DELETE of a row being deleted).  The
general structure of the BEFORE DELETE triggers with cascading logic
was like this:

DECLARE return_value parenttable;
BEGIN return_value := OLD;
 DELETE FROM childtable1   WHERE <child of parent>; IF FOUND THEN   return_value := NULL; END IF;
 DELETE FROM childtablen   WHERE <child of parent>; IF FOUND THEN   return_value := NULL; END IF;
 IF return_value IS NULL THEN   DELETE FROM parent     WHERE <primary key matches OLD>; END IF;
 RETURN return_value;
END;

This did not work for cases where the AFTER DELETE trigger performed
an action which was not idempotent because, while return_value was
NULL enough to enter that last IF clause, it was not NULL enough to
prevent the DELETE attempt and fire subsequent triggers.  The
assignment of NULL to a variable with a record type doesn't assign a
"simple" NULL, but a record with NULL in each element.  It seems
like a POLA violation that:
 return_value := NULL; RETURN return_value;

behaves differently than:
 RETURN NULL;

We've fixed the afflicted trigger functions by adding a RETURN NULL;
inside that last IF block, but:
- Is this behavior required by standard?- If not, do we want to keep this behavior?- If we keep this behavior, should
thetriggering operation be  suppressed when (NOT return_value IS NOT NULL) instead of when  (return_value IS NOT
DISTINCTFROM NULL)?
 

-Kevin



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: PATCH: pgbench - aggregation of info written into log
Next
From: Selena Deckelmann
Date:
Subject: Re: Configuration include directory