*** pgsql/doc/src/sgml/ref/declare.sgml 2008/11/14 10:22:46 1.44 --- pgsql/doc/src/sgml/ref/declare.sgml 2008/11/16 17:34:28 1.45 *************** *** 1,5 **** --- 1,5 ---- *************** DECLARE n *** 214,219 **** --- 214,225 ---- + Backward fetches are also disallowed when the query + includes FOR UPDATE or FOR SHARE; therefore + SCROLL may not be specified in this case. + + + If the cursor's query includes FOR UPDATE or FOR SHARE, then returned rows are locked at the time they are first fetched, in the same way as for a regular *************** DECLARE n *** 221,239 **** these options. In addition, the returned rows will be the most up-to-date versions; therefore these options provide the equivalent of what the SQL standard ! calls a sensitive cursor. It is often wise to use FOR ! UPDATE if the cursor is intended to be used with UPDATE ! ... WHERE CURRENT OF or DELETE ... WHERE CURRENT OF, ! since this will prevent other sessions from changing the rows between ! the time they are fetched and the time they are updated. Without ! FOR UPDATE, a subsequent WHERE CURRENT OF command ! will have no effect if the row was changed meanwhile. ! ! SCROLL may not be specified when the query ! includes FOR UPDATE or FOR SHARE. ! The SQL standard only makes provisions for cursors in embedded --- 227,266 ---- these options. In addition, the returned rows will be the most up-to-date versions; therefore these options provide the equivalent of what the SQL standard ! calls a sensitive cursor. (Specifying INSENSITIVE ! together with FOR UPDATE or FOR SHARE is an error.) ! ! ! It is generally recommended to use FOR UPDATE if the cursor ! is intended to be used with UPDATE ... WHERE CURRENT OF or ! DELETE ... WHERE CURRENT OF. Using FOR UPDATE ! prevents other sessions from changing the rows between the time they are ! fetched and the time they are updated. Without FOR UPDATE, ! a subsequent WHERE CURRENT OF command will have no effect if ! the row was changed since the cursor was created. ! ! ! ! Another reason to use FOR UPDATE is that without it, a ! subsequent WHERE CURRENT OF might fail if the cursor query ! does not meet the SQL standard's rules for being simply ! updatable (in particular, the cursor must reference just one table ! and not use grouping or ORDER BY). Cursors ! that are not simply updatable might work, or might not, depending on plan ! choice details; so in the worst case, an application might work in testing ! and then fail in production. ! ! ! ! The main reason not to use FOR UPDATE with WHERE ! CURRENT OF is if you need the cursor to be scrollable, or to be ! insensitive to the subsequent updates (that is, continue to show the old ! data). If this is a requirement, pay close heed to the caveats shown ! above. ! ! The SQL standard only makes provisions for cursors in embedded