Patch to fix documentation about AFTER triggers

Started by Paul A Jungwirthover 9 years ago3 messageshackers
Jump to latest
#1Paul A Jungwirth
pj@illuminatedcomputing.com

Here is a patch to amend the docs here:

https://www.postgresql.org/docs/devel/static/plpgsql-trigger.html

In the example for an AFTER trigger, you see this code:

--
-- Create a row in emp_audit to reflect the operation performed on emp,
-- make use of the special variable TG_OP to work out the operation.
--
IF (TG_OP = 'DELETE') THEN
INSERT INTO emp_audit SELECT 'D', now(), user, OLD.*;
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
INSERT INTO emp_audit SELECT 'U', now(), user, NEW.*;
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO emp_audit SELECT 'I', now(), user, NEW.*;
RETURN NEW;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger

What are all those RETURNs doing in there? The comment on the final
RETURN is correct, so returning NEW or OLD above seems confusing, and
likely a copy/paste error.

This patch just removes those three lines from the example code.

Thanks!
Paul

Attachments:

plpgsql_trigger_docs_v1.patchtext/x-patch; name=plpgsql_trigger_docs_v1.patchDownload+0-3
#2Ashutosh Bapat
ashutosh.bapat@enterprisedb.com
In reply to: Paul A Jungwirth (#1)
Re: Patch to fix documentation about AFTER triggers

On Sat, May 13, 2017 at 2:45 AM, Paul Jungwirth
<pj@illuminatedcomputing.com> wrote:

Here is a patch to amend the docs here:

https://www.postgresql.org/docs/devel/static/plpgsql-trigger.html

In the example for an AFTER trigger, you see this code:

--
-- Create a row in emp_audit to reflect the operation performed on emp,
-- make use of the special variable TG_OP to work out the operation.
--
IF (TG_OP = 'DELETE') THEN
INSERT INTO emp_audit SELECT 'D', now(), user, OLD.*;
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
INSERT INTO emp_audit SELECT 'U', now(), user, NEW.*;
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO emp_audit SELECT 'I', now(), user, NEW.*;
RETURN NEW;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger

What are all those RETURNs doing in there? The comment on the final RETURN
is correct, so returning NEW or OLD above seems confusing, and likely a
copy/paste error.

This patch just removes those three lines from the example code.

https://www.postgresql.org/docs/devel/static/trigger-definition.html says
"The return value is ignored for row-level triggers fired after an
operation, and so they can return NULL.". There's nothing wrong with
the example, returning OLD or NEW, but as you have pointed out it's
confusing. So, +1 for this change.

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Robert Haas
robertmhaas@gmail.com
In reply to: Ashutosh Bapat (#2)
Re: Patch to fix documentation about AFTER triggers

On Mon, May 15, 2017 at 7:00 AM, Ashutosh Bapat
<ashutosh.bapat@enterprisedb.com> wrote:

On Sat, May 13, 2017 at 2:45 AM, Paul Jungwirth
<pj@illuminatedcomputing.com> wrote:

Here is a patch to amend the docs here:

https://www.postgresql.org/docs/devel/static/plpgsql-trigger.html

In the example for an AFTER trigger, you see this code:

--
-- Create a row in emp_audit to reflect the operation performed on emp,
-- make use of the special variable TG_OP to work out the operation.
--
IF (TG_OP = 'DELETE') THEN
INSERT INTO emp_audit SELECT 'D', now(), user, OLD.*;
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
INSERT INTO emp_audit SELECT 'U', now(), user, NEW.*;
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO emp_audit SELECT 'I', now(), user, NEW.*;
RETURN NEW;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger

What are all those RETURNs doing in there? The comment on the final RETURN
is correct, so returning NEW or OLD above seems confusing, and likely a
copy/paste error.

This patch just removes those three lines from the example code.

https://www.postgresql.org/docs/devel/static/trigger-definition.html says
"The return value is ignored for row-level triggers fired after an
operation, and so they can return NULL.". There's nothing wrong with
the example, returning OLD or NEW, but as you have pointed out it's
confusing. So, +1 for this change.

Committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers