1

I want create a procedure (for copying the values of one table(mover_location) to another table(mover_history) on updation) ,and want to call up on that on a trigger in postgresql with phppgadmin.

Here is what i have tried :

PROCEDURE :-

     CREATE OR REPLACE FUNCTION log_mover_location()
     RETURNS trigger AS

    BEGIN

    INSERT INTO mover_history(reg_id,last_seen_lat,last_seen_long,last_seen_location_geog,last_updated_at)
    VALUES(SELECT 

    mover_location.reg_id,mover_location.last_seen_lat,mover_location.last_seen_long,mover_location.last_seen_location_geog,mover_location.last_updated_at FROM mover_location) WHERE mover_history.reg_id = 

    @mover_location.reg_id;

    END;

TRIGGER :-

CREATE TRIGGER update_mover_history
  AFTER UPDATE
  ON mover_location
  FOR EACH ROW
  EXECUTE PROCEDURE log_mover_location();

Trigger created successfully ,

But it give me a error as follows when executing the procedure:

ERROR:  syntax error at or near "BEGIN"
LINE 4: BEGIN
        ^
KTM
  • 858
  • 4
  • 21
  • 43

1 Answers1

0

the Procedure that you're created is incorrect, for example

CREATE OR REPLACE FUNCTION procedure_name()
RETURNS trigger AS
$BODY$
BEGIN
/*----logic----*/
END
$BODY$
LANGUAGE plpgsql 
Vivek S.
  • 19,945
  • 7
  • 68
  • 85
  • Now the error falls on SELECT as ERROR: syntax error at or near "SELECT" LINE 6: VALUES(SELECT mover_location.reg_id,mover_location.last_seen... ^ – KTM Dec 11 '14 at 12:36