Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max number of collection elements for IN-clause with jpql

Tags:

sql

jpql

I would like to know if there is a limit on the size of a collection when using the IN clause.

select a from A where a.b IN (:c)

and c is a list(for example).

like image 446
Francesco Avatar asked Jan 26 '12 13:01

Francesco


People also ask

Can we use limit in JPQL?

Limiting query results in JPA is slightly different to SQL; we don't include the limit keyword directly into our JPQL. Instead, we just make a single method call to Query#maxResults, or include the keyword first or top in our Spring Data JPA method name.

What is the limit for in clause in Oracle?

In Oracle we can only put up to 1000 values into an IN clause.

How do you limit records in JPA?

Spring Data JPA supports keywords 'first' or 'top' to limit the query results (e.g. findTopBy....). An optional numeric value can be appended after 'top' or 'first' to limit the maximum number of results to be returned (e.g. findTop3By....). If this number is not used then only one entity is returned.


1 Answers

It depends on the specific DBMS, ie. sqlite and postgres have widely different limits (not surprisingly).

EDIT:

For Oracle: How to put more than 1000 values into an Oracle IN clause

For mysql: http://explainextended.com/2009/08/18/passing-parameters-in-mysql-in-list-vs-temporary-table/

like image 57
Savino Sguera Avatar answered Oct 14 '22 09:10

Savino Sguera