1

I am new to PostgreSQL and I am migrating to it from MySQL.Trying to creating Trigger in that.But can't done with it.

This is my MySQL Query.

  delimiter $$
  create trigger delVPNProfile before delete on VPN_Profile_List for each row begin update userinfo set Profile_ID='-1' where Profile_ID=old.Profile_ID; end;$$
  delimiter ;

My PostgreSQL Query is like this.

  $ CREATE FUNCTION make_default_privileges() returns trigger as $$
  begin
  update userinfo set Profile_ID='-1' where Profile_ID=old.Profile_ID;
  end;
  $$ language plpgsql;
  create trigger delVPNProfile before delete on VPN_Profile_List for each row begin EXECUTE PROCEDURE make_default_privileges();
6
  • What specifically is wrong with your PostgreSQL trigger? Syntax errors? Doesn't do what you expect it to? Something else? Commented Feb 29, 2016 at 7:01
  • What is the error message shown? Please provide some more details. Commented Feb 29, 2016 at 7:07
  • One thing I noticed, there is no need to include "begin" in trigger creation syntax. It could be just written as, "..for each row EXECUTE PROCEDURE make_default_privileges();". Commented Feb 29, 2016 at 7:13
  • @muistooshort It doesn't show any error messages.But when I check for crated triggers it doesn't shows any. Commented Feb 29, 2016 at 7:19
  • @Vijay same doesn't work.I am checking the available triggers with select * from pg_trigger; is it right? Commented Feb 29, 2016 at 7:24

1 Answer 1

1
CREATE FUNCTION make_default_privileges() RETURNS trigger AS      $make_default_privileges$
old_id          integer;
BEGIN
old_id=OLD.Profile_ID;
update userinfo set Profile_ID='-1' where Profile_ID=old_id;
RETURN OLD;
END;
   $make_default_privileges$ LANGUAGE plpgsql;

CREATE TRIGGER delVPNProfile before delete on VPN_Profile_List
FOR EACH ROW EXECUTE PROCEDURE make_default_privileges();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.