PostgreSQL Trigger and rows updated

From: Albert <oo_O2_oo(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: PostgreSQL Trigger and rows updated
Date: 2012-03-31 10:39:10
Message-ID: 1333190350056-5608591.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am trying to update a table according to this trigger :

CREATE TRIGGER alert
AFTER UPDATE ON cars
FOR EACH ROW
EXECUTE PROCEDURE update_cars();

Trigger Function :

CREATE FUNCTION update_cars()
RETURNS 'TRIGGER'
AS $BODY$
BEGIN
IF (TG_OP = 'UPDATE') THEN
UPDATE hello_cars SET status = new.status
WHERE OLD.ID = NEW.ID;
END IF;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;

the trigger works fine. when cars table updated, the hello_cars table
updated but status column in each row is updated and contains same new
status ! it must be updated according to car ID.
i think my problem is in condition : WHERE OLD.ID = NEW.ID;
but can't tell what's wrong exactly

Thanks in advanced

--
View this message in context: http://postgresql.1045698.n5.nabble.com/PostgreSQL-Trigger-and-rows-updated-tp5608591p5608591.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Janning Vygen 2012-03-31 11:21:20 Re: PANIC: corrupted item pointer
Previous Message Jeff Davis 2012-03-30 21:00:58 Re: PSQL 9.1.3 segmentation fault