aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2021-04-07 07:49:27 +0200
committerPeter Eisentraut <peter@eisentraut.org>2021-04-07 08:05:55 +0200
commitdd13ad9d39a1ba41cf329b6fe408b49be57c7b88 (patch)
treee75e26cae720ad2f4a0e1d8ef071ae197924c45a /src/backend/parser
parent0b5e8245283eef67e88fb5380836cdc2c743d848 (diff)
downloadpostgresql-dd13ad9d39a1ba41cf329b6fe408b49be57c7b88.tar.gz
postgresql-dd13ad9d39a1ba41cf329b6fe408b49be57c7b88.zip
Fix use of cursor sensitivity terminology
Documentation and comments in code and tests have been using the terms sensitive/insensitive cursor incorrectly relative to the SQL standard. (Cursor sensitivity is only relevant for changes made in the same transaction as the cursor, not for concurrent changes in other sessions.) Moreover, some of the behavior of PostgreSQL is incorrect according to the SQL standard, confusing the issue further. (WHERE CURRENT OF changes are not visible in insensitive cursors, but they should be.) This change corrects the terminology and removes the claim that sensitive cursors are supported. It also adds a test case that checks the insensitive behavior in a "correct" way, using a change command not using WHERE CURRENT OF. Finally, it adds the ASENSITIVE cursor option to select the default asensitive behavior, per SQL standard. There are no changes to cursor behavior in this patch. Discussion: https://www.postgresql.org/message-id/flat/96ee8b30-9889-9e1b-b053-90e10c050e85%40enterprisedb.com
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/analyze.c19
-rw-r--r--src/backend/parser/gram.y5
2 files changed, 17 insertions, 7 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 5de1307570e..bce7a27de00 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -2681,14 +2681,21 @@ transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt)
Query *result;
Query *query;
- /*
- * Don't allow both SCROLL and NO SCROLL to be specified
- */
if ((stmt->options & CURSOR_OPT_SCROLL) &&
(stmt->options & CURSOR_OPT_NO_SCROLL))
ereport(ERROR,
(errcode(ERRCODE_INVALID_CURSOR_DEFINITION),
- errmsg("cannot specify both SCROLL and NO SCROLL")));
+ /* translator: %s is a SQL keyword */
+ errmsg("cannot specify both %s and %s",
+ "SCROLL", "NO SCROLL")));
+
+ if ((stmt->options & CURSOR_OPT_ASENSITIVE) &&
+ (stmt->options & CURSOR_OPT_INSENSITIVE))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_CURSOR_DEFINITION),
+ /* translator: %s is a SQL keyword */
+ errmsg("cannot specify both %s and %s",
+ "ASENSITIVE", "INSENSITIVE")));
/* Transform contained query, not allowing SELECT INTO */
query = transformStmt(pstate, stmt->query);
@@ -2734,10 +2741,10 @@ transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt)
/* FOR UPDATE and INSENSITIVE are not compatible */
if (query->rowMarks != NIL && (stmt->options & CURSOR_OPT_INSENSITIVE))
ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ (errcode(ERRCODE_INVALID_CURSOR_DEFINITION),
/*------
translator: %s is a SQL row locking clause such as FOR UPDATE */
- errmsg("DECLARE INSENSITIVE CURSOR ... %s is not supported",
+ errmsg("DECLARE INSENSITIVE CURSOR ... %s is not valid",
LCS_asString(((RowMarkClause *)
linitial(query->rowMarks))->strength)),
errdetail("Insensitive cursors must be READ ONLY.")));
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 38c36a49360..517bf723784 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -637,7 +637,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
/* ordinary key words in alphabetical order */
%token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
- ASSERTION ASSIGNMENT ASYMMETRIC AT ATTACH ATTRIBUTE AUTHORIZATION
+ ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC AT ATTACH ATTRIBUTE AUTHORIZATION
BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
BOOLEAN_P BOTH BREADTH BY
@@ -11217,6 +11217,7 @@ cursor_options: /*EMPTY*/ { $$ = 0; }
| cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
| cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
| cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
+ | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
| cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
;
@@ -15424,6 +15425,7 @@ unreserved_keyword:
| ALSO
| ALTER
| ALWAYS
+ | ASENSITIVE
| ASSERTION
| ASSIGNMENT
| AT
@@ -15931,6 +15933,7 @@ bare_label_keyword:
| AND
| ANY
| ASC
+ | ASENSITIVE
| ASSERTION
| ASSIGNMENT
| ASYMMETRIC