PostgreSQL - max number of parameters in “IN” clause?

后端 未结 8 1288
無奈伤痛
無奈伤痛 2020-11-28 21:58

In Postgres, you can specify an IN clause, like this:

SELECT * FROM user WHERE id IN (1000, 1001, 1002)

Does anyone know what\'s the maximu

8条回答
  •  萌比男神i
    2020-11-28 22:25

    According to the source code located here, starting at line 850, PostgreSQL doesn't explicitly limit the number of arguments.

    The following is a code comment from line 870:

    /*
     * We try to generate a ScalarArrayOpExpr from IN/NOT IN, but this is only
     * possible if the inputs are all scalars (no RowExprs) and there is a
     * suitable array type available.  If not, we fall back to a boolean
     * condition tree with multiple copies of the lefthand expression.
     * Also, any IN-list items that contain Vars are handled as separate
     * boolean conditions, because that gives the planner more scope for
     * optimization on such clauses.
     *
     * First step: transform all the inputs, and detect whether any are
     * RowExprs or contain Vars.
     */
    

提交回复
热议问题