pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedTrigger function does not modify the NEW value
3+ messages / 2 participants
[nested] [flat]
* Trigger function does not modify the NEW value
@ 2019-06-29 02:53 Igal @ Lucee.org <igal@lucee.org>
2019-06-29 03:07 ` Re: Trigger function does not modify the NEW value David Rowley <david.rowley@2ndquadrant.com>
0 siblings, 1 reply; 3+ messages in thread
From: Igal @ Lucee.org @ 2019-06-29 02:53 UTC (permalink / raw)
To: pgsql-general
I have a trigger that is created like so:
create trigger tr_on_table_modified after insert or delete or update
on some_table for each row execute procedure on_table_modified();
CREATE OR REPLACE FUNCTION on_table_modified() RETURNS trigger
LANGUAGE plpgsql $$
/* some code that does not modify any values but calls PERFORM
on another function */
raise notice 'lowercasing %', new.email;
new.email = lower(new.email);
raise notice ' to %', new.email;
return new;
$$
I can see in the output the notices with the expected values, but the
value in the updated record is not lower-cased.
update some_table
set email = 'IGAL@Lucee.org'
where id = 1;
> 00000: lowercasing IGAL@Lucee.org
> 00000: to igal@lucee.org
select email
from some_table
where id = 1;
> email |
> --------------|
> IGAL@Lucee.org|
Any ideas?
Thanks,
Igal Sapir
Lucee Core Developer
Lucee.org <http://lucee.org/;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Trigger function does not modify the NEW value
2019-06-29 02:53 Trigger function does not modify the NEW value Igal @ Lucee.org <igal@lucee.org>
@ 2019-06-29 03:07 ` David Rowley <david.rowley@2ndquadrant.com>
2019-06-29 03:13 ` Re: Trigger function does not modify the NEW value Igal @ Lucee.org <igal@lucee.org>
0 siblings, 1 reply; 3+ messages in thread
From: David Rowley @ 2019-06-29 03:07 UTC (permalink / raw)
To: Igal @ Lucee.org <igal@lucee.org>; +Cc: pgsql-general
On Sat, 29 Jun 2019 at 14:54, Igal @ Lucee.org <igal@lucee.org> wrote:
> create trigger tr_on_table_modified after insert or delete or update
> on some_table for each row execute procedure on_table_modified();
> I can see in the output the notices with the expected values, but the value in the updated record is not lower-cased.
You'll need a BEFORE trigger, not an AFTER trigger.
https://www.postgresql.org/docs/current/sql-createtrigger.html
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Trigger function does not modify the NEW value
2019-06-29 02:53 Trigger function does not modify the NEW value Igal @ Lucee.org <igal@lucee.org>
2019-06-29 03:07 ` Re: Trigger function does not modify the NEW value David Rowley <david.rowley@2ndquadrant.com>
@ 2019-06-29 03:13 ` Igal @ Lucee.org <igal@lucee.org>
0 siblings, 0 replies; 3+ messages in thread
From: Igal @ Lucee.org @ 2019-06-29 03:13 UTC (permalink / raw)
To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: pgsql-general
On 6/28/2019 8:07 PM, David Rowley wrote:
> On Sat, 29 Jun 2019 at 14:54, Igal @ Lucee.org <igal@lucee.org> wrote:
>> create trigger tr_on_table_modified after insert or delete or update
>> on some_table for each row execute procedure on_table_modified();
>> I can see in the output the notices with the expected values, but the value in the updated record is not lower-cased.
> You'll need a BEFORE trigger, not an AFTER trigger.
> https://www.postgresql.org/docs/current/sql-createtrigger.html
*facepalm*
I was trying to "save" on creating a separate trigger so I added that to
the bottom of an existing one and missed that.
Thanks David!
Igal
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2019-06-29 03:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-06-29 02:53 Trigger function does not modify the NEW value Igal @ Lucee.org <igal@lucee.org>
2019-06-29 03:07 ` David Rowley <david.rowley@2ndquadrant.com>
2019-06-29 03:13 ` Igal @ Lucee.org <igal@lucee.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox