mybatis/velocity-scripting

Support #in directive to render an sql IN clause with more than 1000 items

zaherhammoud opened this issue · 1 comments

Currently mybatis-scripting supports the #repeat directive which iterates through the first 1000 items in a collection and ignores the rest. Most of the time the #repeat directive will be used to render an IN clause and it is not convenient to partially render a collection. Some of the databases such as Oracle have a limit of 1000 items in their IN clause. One way to get around this limitation is to use an OR clause inside the IN .
For example: "WHERE ( (id IN (1,2,....1000)) OR (id IN (1001,1002 ......2000))) ".

I am proposing to add a block #in(Collection $item columnName) directive to mybatis-scripting to handle any collection size. If the collection size is greater than a 1000 , then items will be grouped by 1000 and OR'ed together. It can be used as follow :

SELECT \* FROM MyTable WHERE #in(_param.ids $id "id") @{id} #end

Please note that we do not have to pass the "IN" , "(" , ")" and ","