The app we are building might execute quite a big insert queries. Is there limit that my postgres query can have only a certain number of characters?
PostgreSQL – Maximum Length Constraint for a Query
postgresql
Related Question
- Why LIMIT Affects Postgres Query Performance
- PostgreSQL – Query Planner Not Respecting Table Inheritance Constraint for NULL
- ERROR: Index Row Size Exceeds Maximum for Index in PostgreSQL
- PostgreSQL – How to Get Transaction Commit Timestamp
- PostgreSQL – How to Limit Results for a User
- PostgreSQL Query Performance Issues with COUNT and SORT
- Postgresql – Extremely long postgres query
Best Answer
For current PostgreSQL version (up to 9.5), queries are received by a backend in a
Stringinfo
buffer, which is limited toMaxAllocSize
, defined as:(see http://doxygen.postgresql.org/memutils_8h.html)
So a query is limited to 1 gigabyte (2^30) in size, minus 1 byte for a terminating null byte.
Should a client try to send a larger query, an error looking like this would come back:
where
N
is the size of the query.Be aware that a query just below
1GB
might require large amounts of memory to be parsed, planned or executed, in addition to that1GB
buffer.If you need to push a large series of literals into a query, consider the alternative of creating a temporary table,
COPY
rows into it and have the main query refer to that temporary table.