title: postgres trigger to insert value on when condition
body: <p>I have to write a trigger in postgres 
  trigger should insert values in rp_resourceUser table.</p>
  
  <p>I have three table rp_user, rp_resourceUser, rp_resourceType they all under public schema </p>
  
  <pre><code>fields in rp_user
  user_id bigint NOT NULL,
    is_gtl boolean,
    is_tsc_admin boolean,
    username character varying(255) NOT NULL,
    gtl_user_id bigint,
  
  fields in rp_resource_type
  
    resource_type_id bigint NOT NULL,
    resource_template text,
    resource_type character varying(255),
  
  fields in rp_resource_user_type
  
    resource_user_type_id bigint NOT NULL,
    gtl_user_id bigint NOT NULL,
    resource_type_id bigint NOT NULL,
    user_id bigint NOT NULL,
  
    CONSTRAINT rp_resource_user_type_pkey PRIMARY KEY (resource_user_type_id),
    CONSTRAINT fk6t2cd10tfar76hvvchyo81u66 FOREIGN KEY (user_id)
        REFERENCES public.rp_user (user_id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE NO ACTION,
    CONSTRAINT fkb273dt5c7b9s49jlwf1cmbxib FOREIGN KEY (gtl_user_id)
        REFERENCES public.rp_user (user_id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE NO ACTION,
    CONSTRAINT fkmbxelxexffw96mcgcu3y25ixl FOREIGN KEY (resource_type_id)
        REFERENCES public.rp_resource_type (resource_type_id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE NO ACTION,
    CONSTRAINT uk994khkskqm5c77mlyipwxu0dv UNIQUE (user_id, gtl_user_id, resource_type_id)
  </code></pre>
  
  <p>so condition for trigger would be when gtl flag in user table is set than insert values in rp_resource_user_type </p>
  
  <p>I have wrote something like this </p>
  
  <pre><code>CREATE TRIGGER gtlPermission AFTER UPDATE ON rp_user.is_gtl
  FOR EACH ROW 
  WHEN (public.rp_user.is_gtl IS true)
  EXECUTE PROCEDURE setGtlPermission();
  
  Create or Replace Function setGtlPsermission () RETURNS TRIGGER AS $rp_resource_user_type$
     BEGIN
        INSERT INTO rp_resource_user_type(resource_user_type_id, gtl_user_id, resource_type_id,user_id)
        VALUES (new.resource_user_type_id,  rp_user.gtl_user_id, rp_resource_type.resource_type_id ,rp_user.user_id);
        RETURN NEW;
     END;
  $rp_resource_user_type$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>I never wrote triggers before so i dont even know if thats right .. so needed suggestion </p>