Search Postgresql Archives

Re: PostgreSQL Trigger and rows updated

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	Albert wrote:

>     UPDATE hello_cars SET status = new.status 
>     WHERE OLD.ID = NEW.ID;

[...]

> 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

In this context, OLD.ID and NEW.ID are just variables, and they happen to
have the same value, unless ID is modified.
So the update quoted above is equivalent to:
 UPDATE hello_cars SET status=new.status WHERE value=value
which indeed updates all the rows, not what you want.

The fix would be:
 UPDATE hello_cars SET status=new.status WHERE car_id=NEW.ID;

Best regards,
-- 
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux