Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1njg0t-0005kF-60 for pgsql-docs@arkaria.postgresql.org; Wed, 27 Apr 2022 11:39:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1njg0s-0004dW-0u for pgsql-docs@arkaria.postgresql.org; Wed, 27 Apr 2022 11:39:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1njg0r-0004dK-Of for pgsql-docs@lists.postgresql.org; Wed, 27 Apr 2022 11:39:17 +0000 Received: from mail-yw1-x1129.google.com ([2607:f8b0:4864:20::1129]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1njg0o-0005ue-UW for pgsql-docs@lists.postgresql.org; Wed, 27 Apr 2022 11:39:17 +0000 Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-2f7d19cac0bso14904807b3.13 for ; Wed, 27 Apr 2022 04:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=zG6GAx4WxlugKN4TR+cg3KNqhC/QGQlVlvZlf5UinR0=; b=HIR5DdYFx3kvrsFsVI4yHEdkF5KuXyGDs8xGuOxfeVdaqw+/aMVF218UAi1mf+Q98z GZsHGfsorHrH8iwGyvByd7Wqn33opz9bEgrXt/q2FPoMOoxvANGRp80kDHbHf3+5v32J KIXHMf/0tqP0RAwl7U21VPNk0y3ha1O/LJs2lggILwjfC/mS/WlzY1EUYnPCc/UDm55q 6bClTklMK36U7eESU55LnFiQ9o6NDaAx9fO2kE6h+hWkrhTdurXN7bVWRusZAh/b8hC1 ZObbEQ/+zfNC181h8fgqaQ2QX1m6H2AKYmMFgy4P/cCClgH7joTEaFGSy94euf4D/JCP F5Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=zG6GAx4WxlugKN4TR+cg3KNqhC/QGQlVlvZlf5UinR0=; b=CjzH8r1482EvlmZEYiWz5gQquUeY+FtsvSe6zcnLBFYf4S6RvsNQCjI3a4xfZlB2MJ V6mabrVVa/ot4gvBLwNqihgpHlxWeC9DGk57+EtFGE1iJ+VRfOhSYgM0LUPT58VSWkvs voKKrHkXE+IGN8PNuvmaLAbwETxF8NoEdaxvfTUIYAq/bvaTGcDzMigLDuo7cl/LJzNk DxXWgzFn3UjcO6qWH8lhBJPflBDinazkdtvqmKvx+KfBXdSs/lxEUos/3rQRo52EsNgT VE4y+i87+Ljy1jaXryvvv3aZZ1qb0J0sLg9+Uaixl4FVWYzrCLXkQKv1AENFGZ0jg4kV ZJag== X-Gm-Message-State: AOAM530c/oonyxJPzhjLyQ6egIW3OQg9csW4kgLcEoJTBCFFK/mUm5OY u4Gkm43e5KDzqx1rKljoa8iINDLThq+wzK2HDEdgfs21XZAdrA== X-Google-Smtp-Source: ABdhPJwacs0aw8xWOKnVfJT0XmxsFcTQkWZkxBQ7W9ansNo+K5jGUkH9pWSgabuBcq5W+NPhtCHBrwetyBsNWXQYtX0= X-Received: by 2002:a0d:d64f:0:b0:2f4:e34f:3e68 with SMTP id y76-20020a0dd64f000000b002f4e34f3e68mr26980854ywd.187.1651059553113; Wed, 27 Apr 2022 04:39:13 -0700 (PDT) MIME-Version: 1.0 From: Jian He Date: Wed, 27 Apr 2022 17:09:01 +0530 Message-ID: Subject: 43.10 Trigger Functions one sentences kind of not easy to understand. To: pgsql-docs@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000002a9a3705dda1421b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002a9a3705dda1421b Content-Type: text/plain; charset="UTF-8" https://www.postgresql.org/docs/current/plpgsql-trigger.html > > Row-level triggers fired BEFORE can return null to signal the trigger > manager to skip the rest of the operation for this row (i.e., subsequent > triggers are not fired, and the INSERT/UPDATE/DELETE does not occur for > this row). If a nonnull value is returned then the operation proceeds with > that row value. *Returning a row value different from the original value > of NEW alters the row that will be inserted or updated. *Thus, if the > trigger function wants the triggering action to succeed normally without > altering the row value, NEW (or a value equal thereto) has to be > returned. To alter the row to be stored, it is possible to replace single > values directly in NEW and return the modified NEW, or to build a > complete new record/row to return. In the case of a before-trigger on > DELETE, the returned value has no direct effect, but it has to be nonnull > to allow the trigger action to proceed. Note that NEW is null in DELETE > triggers, so returning that is usually not sensible. The usual idiom in > DELETE triggers is to return OLD. > I just want confirm the highlighted sentence is equivalent as the following sql code: begin; > CREATE TABLE documents ( > docdesc text, > misc text, > modification_time timestamp with time zone DEFAULT now() > ); > CREATE FUNCTION documents_update_mod_time() RETURNS trigger > AS $$ > begin > new.modification_time := now(); > return new; > end > $$ > LANGUAGE plpgsql; > CREATE TRIGGER documents_modification_time > BEFORE INSERT OR UPDATE ON documents > FOR EACH ROW > EXECUTE PROCEDURE documents_update_mod_time(); > commit; > as a non-native english speaker, I kind of feel this sentence quite hard to understand.... --0000000000002a9a3705dda1421b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

<= /div>
Row-level triggers fired BEFORE can return null to signal the trigger manager to skip the rest of the=20 operation for this row (i.e., subsequent triggers are not fired, and the INSERT/<= code class=3D"gmail-command" style=3D"user-select: text;">UPDATE/DELETE does not occur for this row). If a nonnull value is returned then the=20 operation proceeds with that row value. Returning a row value different=20 from the original value of NEW alters the row that will be inserted or updated. Thus, if the trigger=20 function wants the triggering action to succeed normally without=20 altering the row value, NEW (or a value equal thereto) has to be returned. To alter the row to be=20 stored, it is possible to replace single values directly in NEW and return the modif= ied NEW, = or to build a complete new record/row to return. In the case of a before-tr= igger on DELETE<= /code>, the returned value has no direct effect, but it has to be nonnull t= o allow the trigger action to proceed. Note that NEW is null in DELETE triggers, so returning= that is usually not sensible. The usual idiom in DELETE triggers is to return OLD.

I just want confirm the highlighted sentence=C2= =A0 is equivalent as the following sql code:

begin;
CREATE TABLE documen= ts (
=C2=A0 =C2=A0 docdesc text,
=C2=A0 =C2=A0 misc text,
=C2=A0 = =C2=A0 modification_time timestamp with time zone DEFAULT now()
);
CR= EATE FUNCTION documents_update_mod_time() RETURNS trigger
AS $$
=C2= =A0 =C2=A0 begin
=C2=A0 =C2=A0 new.modification_time :=3D now();=C2=A0
=C2= =A0=C2=A0=C2=A0 return new;
=C2=A0 =C2=A0 end
$$
=C2=A0 =C2=A0 LANG= UAGE plpgsql;
CREATE TRIGGER documents_modification_time
=C2=A0 =C2= =A0 BEFORE INSERT OR UPDATE ON documents
=C2=A0 =C2=A0 FOR EACH ROW
= =C2=A0 =C2=A0 EXECUTE PROCEDURE documents_update_mod_time();
commit;
=

as a non-native english speaker, I k= ind of feel this sentence quite hard to understand....
=C2= =A0
--0000000000002a9a3705dda1421b--