L.Nelson L.Nelson - 5 months ago 25
MySQL Question

Convertion of MySQL Triggers to PostgreSql Trigger

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.

Answer

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.

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
Comments