Is there any size limitation of SQL result?

Viewed 114

I am using Azure PostgreSQL, I have a lot of files saved as byeta datatype in a table. In my project, I will execute some SQL query to get these files.

Sometimes a query will involve multiple files so the result data size of SQL query will be large. My questions: is there has some data size limit of SQL result for one SQL query ? Should I do some limit here? Any suggestion is appreciated.

1 Answers

There is no limit for the size of a result set in PostgreSQL.

However, many clients cache the whole result set in memory, which can easily lead to an out-of-memory condition on the client side.

There are ways around that:

  • Use cursors and fetch the result row by row or in batches. That should work with any client API.

  • With the C API (libpq), you could activate single-row mode.

  • With JDBC, you could set the fetch size.

Note that this means that you could get a runtime error from the database server in the middle of processing a result set.

Related