From 54f7338fa119802cabb12f7fc0020a167d9690c0 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 27 Mar 2003 16:51:29 +0000 Subject: This patch implements holdable cursors, following the proposal (materialization into a tuple store) discussed on pgsql-hackers earlier. I've updated the documentation and the regression tests. Notes on the implementation: - I needed to change the tuple store API slightly -- it assumes that it won't be used to hold data across transaction boundaries, so the temp files that it uses for on-disk storage are automatically reclaimed at end-of-transaction. I added a flag to tuplestore_begin_heap() to control this behavior. Is changing the tuple store API in this fashion OK? - in order to store executor results in a tuple store, I added a new CommandDest. This works well for the most part, with one exception: the current DestFunction API doesn't provide enough information to allow the Executor to store results into an arbitrary tuple store (where the particular tuple store to use is chosen by the call site of ExecutorRun). To workaround this, I've temporarily hacked up a solution that works, but is not ideal: since the receiveTuple DestFunction is passed the portal name, we can use that to lookup the Portal data structure for the cursor and then use that to get at the tuple store the Portal is using. This unnecessarily ties the Portal code with the tupleReceiver code, but it works... The proper fix for this is probably to change the DestFunction API -- Tom suggested passing the full QueryDesc to the receiveTuple function. In that case, callers of ExecutorRun could "subclass" QueryDesc to add any additional fields that their particular CommandDest needed to get access to. This approach would work, but I'd like to think about it for a little bit longer before deciding which route to go. In the mean time, the code works fine, so I don't think a fix is urgent. - (semi-related) I added a NO SCROLL keyword to DECLARE CURSOR, and adjusted the behavior of SCROLL in accordance with the discussion on -hackers. - (unrelated) Cleaned up some SGML markup in sql.sgml, copy.sgml Neil Conway --- doc/src/sgml/ref/fetch.sgml | 53 ++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'doc/src/sgml/ref/fetch.sgml') diff --git a/doc/src/sgml/ref/fetch.sgml b/doc/src/sgml/ref/fetch.sgml index 8f3244eb39f..a1f3b13719f 100644 --- a/doc/src/sgml/ref/fetch.sgml +++ b/doc/src/sgml/ref/fetch.sgml @@ -1,5 +1,5 @@ @@ -251,8 +251,7 @@ WARNING: PerformPortalFetch: portal "cursor - If cursor is not known. - The cursor must have been declared within the current transaction block. + There is no cursor with the specified name. @@ -326,7 +325,9 @@ WARNING: PerformPortalFetch: portal "cursorFETCH other than FETCH NEXT or FETCH FORWARD with a positive count. For simple queries PostgreSQL will allow backwards fetch from - cursors not declared with SCROLL, but this behavior is best not relied on. + cursors not declared with SCROLL, but this behavior is best not + relied on. If the cursor is declared with NO SCROLL, no backward + fetches are allowed. @@ -339,16 +340,11 @@ WARNING: PerformPortalFetch: portal "cursor - Updating data via a cursor is not supported by - PostgreSQL, - because mapping cursor updates back to base tables is - not generally possible, as is also the case with VIEW updates. - Consequently, - users must issue explicit UPDATE commands to replace data. - - - - Cursors may only be used inside transaction blocks. + Updating data via a cursor is not supported by + PostgreSQL, because mapping cursor + updates back to base tables is not generally possible, as is also + the case with view updates. Consequently, users must issue + explicit UPDATE commands to replace data. @@ -357,12 +353,6 @@ WARNING: PerformPortalFetch: portal "cursor to change cursor position without retrieving data. - Refer to - , - , - and - - for further information about transactions. @@ -379,7 +369,7 @@ WARNING: PerformPortalFetch: portal "cursor - SQL92 defines FETCH for use in embedded contexts only. - Therefore, it describes placing the results into explicit variables using - an INTO clause, for example: + SQL92 defines FETCH for use + in embedded contexts only. Therefore, it describes placing the + results into explicit variables using an INTO clause, + for example: FETCH ABSOLUTE n @@ -435,16 +426,18 @@ FETCH ABSOLUTE n INTO :variable [, ...] - PostgreSQL's use of non-embedded cursors - is non-standard, and so is its practice of returning the result data - as if it were a SELECT result. Other than this point, FETCH is fully + PostgreSQL's use of non-embedded + cursors is non-standard, and so is its practice of returning the + result data as if it were a SELECT result. + Other than this point, FETCH is fully upward-compatible with SQL92. - The FETCH forms involving FORWARD and BACKWARD (including the forms - FETCH count and FETCH ALL, - in which FORWARD is implicit) are PostgreSQL + The FETCH forms involving FORWARD and BACKWARD + (including the forms FETCH count and FETCH ALL, in which + FORWARD is implicit) are PostgreSQL extensions. -- cgit v1.2.3