Using “IN” in a WHERE clause where the number of items in the set is very large

前端 未结 10 2400
梦毁少年i
梦毁少年i 2021-02-13 05:30

I have a situation where I need to do an update on a very large set of rows that I can only identify by their ID (since the target records are selected by the user and have noth

10条回答
  •  不思量自难忘°
    2021-02-13 06:24

    I would always use

    WHERE id IN (1,2,3,4,.....10000)
    

    unless your in clause was stupidly large, which shouldn't really happen from user input.

    edit: For instance, Rails does this a lot behind the scenes

    It would definitely not be better to do separate update statements in a single transaction.

提交回复
热议问题