Perform a
SELECT or other SQL query that is expected to
return results. Results are streamed incrementally from the server,
and consumed via a left fold.
When dealing with small results, it may be simpler (and perhaps
faster) to use
query instead.
This fold is
not strict. The stream consumer is responsible for
forcing the evaluation of its result to avoid space leaks.
This is implemented using a database cursor. As such, this requires a
transaction. This function will detect whether or not there is a
transaction in progress, and will create a
ReadCommitted
ReadOnly transaction if needed. The cursor is given a unique
temporary name, so the consumer may itself call fold.
Exceptions that may be thrown:
- FormatError: the query string could not be formatted
correctly.
- QueryError: the result contains no columns (i.e. you should
be using execute instead of query).
- ResultError: result conversion failed.
- SqlError: the postgresql backend returned an error, e.g. a
syntax or type error, or an incorrect table or column name.