Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In mysql or postgres, is there a limit to the size of an IN (1,2,n) statement?

I've got quite a few SQL statements like such:

SELECT foo FROM things WHERE user_id IN (1,2,3..n)

Is there a known limit to the number of elements that will safely fit in an IN clause like that?

like image 469
Kyle Avatar asked Mar 11 '10 15:03

Kyle


1 Answers

The 1000 limit in PostgreSQL is not a hard limit, it is a optimization limit, i.e; after 1000 PostgreSQL doesn't handle it very well. Of course I have to ask what in the world are you doing with a 1000 entry IN clause.

like image 80
Joshua D. Drake Avatar answered Oct 21 '22 09:10

Joshua D. Drake