pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Jungwirth <pj@illuminatedcomputing.com>
To: Pgsql Hackers <pgsql-hackers@postgresql.org>
Subject: Patch to fix documentation about AFTER triggers
Date: Fri, 12 May 2017 14:15:37 -0700
Message-ID: <e24a6a6d-5670-739b-00f3-41a226a80f25@illuminatedcomputing.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

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

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

Attachments:

plpgsql_trigger_docs_v1.patch (text/x-patch, 765B) download diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index a6088e9..dc29e7c 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -3999,13 +3999,10 @@ CREATE OR REPLACE FUNCTION process_emp_audit() RETURNS TRIGGER AS $emp_audit$ -- 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 END;

view thread (3+ messages)  latest in thread

Message-ID: <e24a6a6d-5670-739b-00f3-41a226a80f25@illuminatedcomputing.com>
Permalink:  ../e24a6a6d-5670-739b-00f3-41a226a80f25@illuminatedcomputing.com/
Also on:    postgresql.org/message-id/e24a6a6d-5670-739b-00f3-41a226a80f25@illuminatedcomputing.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: pj@illuminatedcomputing.com
  Subject: Re: Patch to fix documentation about AFTER triggers
  In-Reply-To: <e24a6a6d-5670-739b-00f3-41a226a80f25@illuminatedcomputing.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox