将MySQL触发器转换为PostgreSql触发器

时间:2021-04-16 22:57:52

I am working with pgsql and i need to convert my mysql trigger to pgsql trigger.Pgsql query has executed successfully,but i am not able to view output.Please help me.

我正在使用pgsql,我需要将我的mysql触发器转换为pgsql trigger.Pgsql查询已成功执行,但我无法查看输出。请帮助我。

1 个解决方案

#1


1  

The code of trigger looks well. I don't see any problem. When you design trigger, then the RAISE NOTICE statement is your best friend. The often error is human error - you can set trigger on wrong table, you can try to insert to wrong table - the notification shows so all is ok.

触发器代码看起来很好。我没有看到任何问题。当您设计触发器时,RAISE NOTICE语句是您最好的朋友。经常出错是人为错误 - 你可以在错误的表上设置触发器,你可以尝试插入错误的表 - 通知显示所以一切正常。

postgres=> \sf func_trg 
CREATE OR REPLACE FUNCTION public.func_trg()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$
BEGIN
  RAISE NOTICE 'func_trg: %', new;
  RETURN new;
END;
$function$

postgres=> CREATE TRIGGER xxx AFTER INSERT ON foo_table
                FOR EACH ROW EXECUTE PROCEDURE func_trg();
CREATE TRIGGER
postgres=> set client_min_messages to notice;
SET
postgres=> INSERT INTO foo_table VALUES(10,20);
NOTICE:  func_trg: (10,20)
INSERT 0 1

#1


1  

The code of trigger looks well. I don't see any problem. When you design trigger, then the RAISE NOTICE statement is your best friend. The often error is human error - you can set trigger on wrong table, you can try to insert to wrong table - the notification shows so all is ok.

触发器代码看起来很好。我没有看到任何问题。当您设计触发器时,RAISE NOTICE语句是您最好的朋友。经常出错是人为错误 - 你可以在错误的表上设置触发器,你可以尝试插入错误的表 - 通知显示所以一切正常。

postgres=> \sf func_trg 
CREATE OR REPLACE FUNCTION public.func_trg()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$
BEGIN
  RAISE NOTICE 'func_trg: %', new;
  RETURN new;
END;
$function$

postgres=> CREATE TRIGGER xxx AFTER INSERT ON foo_table
                FOR EACH ROW EXECUTE PROCEDURE func_trg();
CREATE TRIGGER
postgres=> set client_min_messages to notice;
SET
postgres=> INSERT INTO foo_table VALUES(10,20);
NOTICE:  func_trg: (10,20)
INSERT 0 1