Maximum length of an SQL Query Maximum length of an SQL Query ruby ruby

Maximum length of an SQL Query


The maximum length of a query that PostgreSQL can process is 2147483648 characters (signed 4-byte integer; see src/include/lib/stringinfo.h).


To avoid the query size, you could replace the IN (1, 2) with IN (select followed_id from following where follower_id = ?) or whatever the appropriate query would be to find the ids of the followed users from the follower's id.


While there is no (real) limit on the length of the query string, there is a limit on the number of IN (x,y,z...) clauses: 10000, configurable in the postgres.ini-file:

See:http://grokbase.com/t/postgresql/pgsql-general/061mc7pxg6/what-is-the-maximum-length-of-an-in-a-b-c-d-list-in-postgresql :

"In 7.4 and earlier it depends on the max_expr_depth setting."..."In 8.0 and later max_expr_depth is gone and the limit depends onmax_stack_depth."