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