Skip to content

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

@zaherhammoud

Description

@zaherhammoud

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 ","

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions