Re: trigger impacting insertion of records - Mailing list pgsql-general

From Michael Lewis
Subject Re: trigger impacting insertion of records
Date
Msg-id CAHOFxGpnMbwyzUTL5BBQYwC5rgdCFztYJojS4V8Aa0ovaK=3bw@mail.gmail.com
Whole thread Raw
In response to trigger impacting insertion of records  (Atul Kumar <akumar14871@gmail.com>)
List pgsql-general
It seems like there is some flaw here. From my reading, on insert of any row, you are updating ALL rows in the same table to just remove an underscore if it matches the pattern of 'US_' at the beginning. That doesn't seem likely to be what you want. I'd think you would want something like the below.

CREATE OR REPLACE FUNCTION bonzipay.ussf_accountnumber_update()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$ BEGIN
if( left(NEW.accountnumber,3) = 'US_' ) then
NEW.accountnumber=replace(accountnumber,'_',' ');
RETURN NEW; END; $function$

pgsql-general by date:

Previous
From: Michael Nolan
Date:
Subject: Re: Copyright vs Licence
Next
From: Jonathan Chen
Date:
Subject: Postgresql 13 query engine regression