fold package:postgresql-simple

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.
A version of fold taking a parser as an argument
The same as fold, but this provides a bit more control over lower-level details. Currently, the number of rows fetched per round-trip to the server and the transaction mode may be adjusted accordingly. If the connection is already in a transaction, then the existing transaction is used and thus the transactionMode option is ignored.
A version of foldWithOptions taking a parser as an argument
A version of foldWithOptions_ taking a parser as an argument
A version of fold_ taking a parser as an argument
A version of fold that does not perform query substitution.
Fold over COPY TO STDOUT query passing each copied row to an accumulator and calling a post-process at the end. A connection must be in the CopyOut state in order to call this function. Example
(acc, count) <- foldCopyData conn
(\acc row -> return (row:acc))
(\acc count -> return (acc, count))
[]
Fold over a chunk of rows, calling the supplied fold-like function on each row as it is received. In case the cursor is exhausted, a Left value is returned, otherwise a Right value is returned.
Fold over a chunk of rows from the given cursor, calling the supplied fold-like function on each row as it is received. In case the cursor is exhausted, a Left value is returned, otherwise a Right value is returned.