Cursors

Most advanced modern database systems provide what are known as cursors. The main advantage of cursors is that the result is returned to the client as one recordset. Whenever the next value in a cursor is requested, the database computes it in real time and returns it to the client. In other words: The result of a query is generated and returned line by line. The client has to store exactly one line of data. Whenever it's necessary to process gigabytes of data, cursors are essential because otherwise it will be hard to keep the entire recordset in memory.

In the next example, you can see how cursors work. We use the interactive command shell (psql) to see what you have to do:

 mono=# DECLARE mycurs CURSOR FOR SELECT 1+1 UNION SELECT 2+2; ...

Get Mono Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.