public inbox for [email protected]
help / color / mirror / Atom feedFrom: Andreas Kretschmer <[email protected]>
To: [email protected]
Subject: Re: Writing my first trigger
Date: Sat, 21 May 2022 15:36:15 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <CAPhBOiiW8jk_2wcKvCik1eXNejS10qwfGuuovPk0Q=5kvHNxNw@mail.gmail.com>
<[email protected]>
Am 20.05.22 um 17:06 schrieb Andreas Kretschmer:
>
> your table doesn't contain the field "updatedA". I would suggest to
> calculate the fullName at select-time and not via TRIGGER.
other solution, generated colums:
postgres=# create table employee (firstname text, prefered_firstname
text, lastname text, fullname text generated always as
(coalesce(prefered_firstname,firstname) || ' ' || lastname) stored);
CREATE TABLE
postgres=#
postgres=#
postgres=# insert into employee values ('max',null, 'mueller');
INSERT 0 1
postgres=# insert into employee values ('susann','susi', 'scholz');
INSERT 0 1
postgres=# select * from employee ;
firstname | prefered_firstname | lastname | fullname
-----------+--------------------+----------+-------------
max | | mueller | max mueller
susann | susi | scholz | susi scholz
(2 rows)
postgres=#
Regards, Andreas
--
2ndQuadrant, an EDB company
www.2ndQuadrant.com / www.enterprisedb.com
view thread (6+ messages)
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: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Writing my first trigger
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox