1

On UPDATE query I would like to change need_parse attribute if url attribute was changed. need_parse depends on url value.

How can I achieve this on MySQL & Python?

DjangoPy
  • 855
  • 1
  • 13
  • 29
  • On update, do you want to change need_parse attribute, only if url attribute is changed, Otherwise do not execute the update query, Is it what you want? Say, update query is to change the need_parse attribute, then you want if that update also involves change in url attribute. If yes, then execute the update query on need_parse attribute else not? Is it what you want? Or something else? – jsist Jul 28 '12 at 08:56
  • I always want to perform the update but i want to update need_parse attribute if and only if url attribute was changed. all other attribute will be updated even if their values did not change. – DjangoPy Jul 28 '12 at 09:02
  • Solution: use trigger - see [reference ][1] [1]: http://stackoverflow.com/questions/6296313/mysql-trigger-after-update-only-if-row-has-changed?rq=1 – DjangoPy Jul 28 '12 at 09:59

2 Answers2

0

Perhaps you need something like:

UPDATE tbl
SET need_parse = CASE WHEN url = <input url> THEN need_parse ELSE <value to change to> END
Zane Bien
  • 22,685
  • 6
  • 45
  • 57
  • I created a trigger for such thing. This was my reference: http://stackoverflow.com/questions/6296313/mysql-trigger-after-update-only-if-row-has-changed?rq=1 – DjangoPy Jul 28 '12 at 09:33
0

You can use the following trigger to put check on updates. It will do what you require

DELIMITER $$

CREATE
    TRIGGER `test`.`update_check` BEFORE UPDATE
    ON `db_name`.`table_name`
    FOR EACH ROW BEGIN
    IF (new.`url` = old.`url`)
    THEN SET new.`need_parse` = old.`need_parse`;
    END IF;
    END$$
DELIMITER ;

Hope it helps...

jsist
  • 5,223
  • 3
  • 28
  • 43