Re: trigger impacting insertion of records

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Atul Kumar <akumar14871(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: trigger impacting insertion of records
Date: 2021-05-10 19:16:49
Message-ID: CAHOFxGpnMbwyzUTL5BBQYwC5rgdCFztYJojS4V8Aa0ovaK=3bw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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$

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Chen 2021-05-10 21:13:20 Postgresql 13 query engine regression
Previous Message Michael Nolan 2021-05-10 16:08:19 Re: Copyright vs Licence