Re: 43.10 Trigger Functions one sentences kind of not easy to understand.

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Jian He <hejian(dot)mark(at)gmail(dot)com>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: 43.10 Trigger Functions one sentences kind of not easy to understand.
Date: 2022-04-27 11:46:05
Message-ID: 202204271146.waevseyzqnsb@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On 2022-Apr-27, Jian He wrote:

> https://www.postgresql.org/docs/current/plpgsql-trigger.html
>
> > *Returning a row value different from the original value
> > of NEW alters the row that will be inserted or updated.*

> I just want confirm the highlighted sentence is equivalent as the
> following sql code:

Yes:

> 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;

This is the usual way to modify the row being inserted.

> As a non-native english speaker, I kind of feel this sentence quite hard to
> understand....

Maybe you can split it up at periods and think about individual parts
separately. The docs are intentionally packed very densely with
information, to avoid making them longer than they already are.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2022-04-27 14:45:36 Mixed field in table 70.3
Previous Message Jian He 2022-04-27 11:39:01 43.10 Trigger Functions one sentences kind of not easy to understand.