![]() ![]() If FOR UPDATE is specified, the cursor is guaranteed to be updatable. 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. Without FOR UPDATE, a subsequent WHERE CURRENT OF command will have no effect if the row was changed since the cursor was created.Īnother 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). Using FOR UPDATE prevents other sessions from changing the rows between the time they are fetched and the time they are updated. It is generally recommended to use FOR UPDATE if the cursor is intended to be used with UPDATE. If NO SCROLL is specified, then backward fetches are disallowed in any case.īackward fetches are also disallowed when the query includes FOR UPDATE or FOR SHARE therefore SCROLL may not be specified in this case. However, application developers are advised not to rely on using backward fetches from a cursor that has not been created with SCROLL. However, for compatibility with earlier versions, PostgreSQL will allow backward fetches without SCROLL, if the cursor's query plan is simple enough that no extra overhead is needed to support it. The SCROLL option should be specified when defining a cursor that will be used to fetch backwards. ![]() ![]() WITH HOLD may not be specified when the query includes FOR UPDATE or FOR SHARE. In the current implementation, the rows represented by a held cursor are copied into a temporary file or memory area so that they remain available for subsequent transactions. (But if the creating transaction is aborted, the cursor is removed.) A cursor created with WITH HOLD is closed when an explicit CLOSE command is issued on it, or the session ends. If WITH HOLD is specified and the transaction that created the cursor successfully commits, the cursor can continue to be accessed by subsequent transactions in the same session. Use BEGIN and COMMIT (or ROLLBACK) to define a transaction block. Therefore PostgreSQL reports an error if such a command is used outside a transaction block. Thus, DECLARE without WITH HOLD is useless outside a transaction block: the cursor would survive only to the completion of the statement. Unless WITH HOLD is specified, the cursor created by this command can only be used within the current transaction. ![]() The concept of a binary cursor as such is thus obsolete when using extended query protocol - any cursor can be treated as either text or binary. This choice overrides the way that the cursor is defined. When the client application uses the “ extended query” protocol to issue a FETCH command, the Bind protocol message specifies whether data is to be retrieved in text or binary format. The key words ASENSITIVE, BINARY, INSENSITIVE, and SCROLL can appear in any order. queryĪ SELECT or VALUES command which will provide the rows to be returned by the cursor. If neither WITHOUT HOLD nor WITH HOLD is specified, WITHOUT HOLD is the default. WITHOUT HOLD specifies that the cursor cannot be used outside of the transaction that created it. WITH HOLD specifies that the cursor can continue to be used after the transaction that created it successfully commits. The default is to allow scrolling in some cases this is not the same as specifying SCROLL. NO SCROLL specifies that the cursor cannot be used to retrieve rows in a nonsequential fashion. Depending upon the complexity of the query's execution plan, specifying SCROLL might impose a performance penalty on the query's execution time. SCROLL specifies that the cursor can be used to retrieve rows in a nonsequential fashion (e.g., backward). Specifying INSENSITIVE together with FOR UPDATE or FOR SHARE is an error. In PostgreSQL, all cursors are insensitive so these key words have no effect and are only accepted for compatibility with the SQL standard. A third behavior, SENSITIVE, meaning that such changes are visible in the cursor, is not available in PostgreSQL. INSENSITIVE means they are not visible, ASENSITIVE means the behavior is implementation-dependent. ASENSITIVEĬursor sensitivity determines whether changes to the data underlying the cursor, done in the same transaction, after the cursor has been declared, are visible in the cursor. BINARYĬauses the cursor to return data in binary rather than in text format. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |