Re: Writing my first trigger

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: Re: Writing my first trigger
Date: 2022-05-21 13:36:15
Message-ID: 010d77a8-4338-5dc0-d055-e25782ef825c@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Scott Holliday 2022-06-06 17:22:02 SQL question, TOP 5 and all OTHERS
Previous Message Andreas Kretschmer 2022-05-20 15:06:11 Re: Writing my first trigger