MySQL Forums
Forum List  »  Triggers

Update ... Where In() not working in trigger
Posted by: Steve Angel
Date: June 02, 2011 05:53AM

I have an after insert trigger that should update another table using a comma separated list from the inserted row, but the update statement only updates the first value ...

Example:

I insert a new row to run the trigger -
e.g. INSERT INTO table1 (id,other_ids) VALUES (null,'1,2,3')

The id field is an auto increment primary key, the other_ids field is a text field.

The trigger is set to run the following after insert on table1 ...
UPDATE table2 SET temp_id = new.id WHERE id IN(new.other_ids);

... but it will only update the first id in the comma separated list.

I'm guessing it's treating new.other_ids as an INT, but I've tried various different ways of casting as char or binary and still nothing works.

I have managed to temporarily get around the problem by creating a split string function that splits out the ids from the comma separated list and updates them individually but this isn't ideal.

Is there any way to make the above UPDATE ... WHERE IN() statement work?

MySQL version is 5.0.77. Maybe this is a bug with this version?

Options: Reply• Quote


Subject
Views
Written By
Posted
Update ... Where In() not working in trigger
4453
June 02, 2011 05:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.