Commit bcb5aac8 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Add keywords to implement Vadim's transaction isolation

 and lock syntax as fully parsed tokens.
Two keywords for isolation are non-reserved SQL92
 (COMMITTED, SERIALIZABLE).
All other new keywords are non-reserved Postgres (not SQL92)
 (ACCESS, EXCLUSIVE, MODE, SHARE).
Add syntax to allow CREATE [GLOBAL|LOCAL] TEMPORARY TABLE, throwing an
 error if GLOBAL is specified.
parent 3ce054b5
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.73 1999/05/11 03:28:42 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.74 1999/05/12 07:22:51 thomas Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -138,7 +138,8 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -138,7 +138,8 @@ Oid param_type(int t); /* used in parse_expr.c */
%type <str> opt_database1, opt_database2, location, encoding %type <str> opt_database1, opt_database2, location, encoding
%type <str> opt_lmode %type <ival> opt_lock, lock_type
%type <boolean> opt_lmode
%type <pboolean> user_createdb_clause, user_createuser_clause %type <pboolean> user_createdb_clause, user_createuser_clause
%type <str> user_passwd_clause %type <str> user_passwd_clause
...@@ -157,6 +158,7 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -157,6 +158,7 @@ Oid param_type(int t); /* used in parse_expr.c */
all_Op, MathOp, opt_name, opt_unique, all_Op, MathOp, opt_name, opt_unique,
OptUseOp, opt_class, SpecialRuleRelation OptUseOp, opt_class, SpecialRuleRelation
%type <str> opt_level
%type <str> privileges, operation_commalist, grantee %type <str> privileges, operation_commalist, grantee
%type <chr> operation, TriggerOneEvent %type <chr> operation, TriggerOneEvent
...@@ -175,7 +177,7 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -175,7 +177,7 @@ Oid param_type(int t); /* used in parse_expr.c */
%type <node> func_return %type <node> func_return
%type <boolean> set_opt %type <boolean> set_opt
%type <boolean> TriggerForOpt, TriggerForType, OptTemp %type <boolean> TriggerForOpt, TriggerForType, OptTemp, OptTempType, OptTempScope
%type <list> for_update_clause, update_list %type <list> for_update_clause, update_list
%type <boolean> opt_union %type <boolean> opt_union
...@@ -280,7 +282,7 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -280,7 +282,7 @@ Oid param_type(int t); /* used in parse_expr.c */
DAY_P, DECIMAL, DECLARE, DEFAULT, DELETE, DESC, DISTINCT, DOUBLE, DROP, DAY_P, DECIMAL, DECLARE, DEFAULT, DELETE, DESC, DISTINCT, DOUBLE, DROP,
ELSE, END_TRANS, EXCEPT, EXECUTE, EXISTS, EXTRACT, ELSE, END_TRANS, EXCEPT, EXECUTE, EXISTS, EXTRACT,
FALSE_P, FETCH, FLOAT, FOR, FOREIGN, FROM, FULL, FALSE_P, FETCH, FLOAT, FOR, FOREIGN, FROM, FULL,
GRANT, GROUP, HAVING, HOUR_P, GLOBAL, GRANT, GROUP, HAVING, HOUR_P,
IN, INNER_P, INSENSITIVE, INSERT, INTERSECT, INTERVAL, INTO, IS, IN, INNER_P, INSENSITIVE, INSERT, INTERSECT, INTERVAL, INTO, IS,
ISOLATION, JOIN, KEY, LANGUAGE, LEADING, LEFT, LEVEL, LIKE, LOCAL, ISOLATION, JOIN, KEY, LANGUAGE, LEADING, LEFT, LEVEL, LIKE, LOCAL,
MATCH, MINUTE_P, MONTH_P, NAMES, MATCH, MINUTE_P, MONTH_P, NAMES,
...@@ -299,7 +301,7 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -299,7 +301,7 @@ Oid param_type(int t); /* used in parse_expr.c */
%token TRIGGER %token TRIGGER
/* Keywords (in SQL92 non-reserved words) */ /* Keywords (in SQL92 non-reserved words) */
%token TYPE_P %token COMMITTED, SERIALIZABLE, TYPE_P
/* Keywords for Postgres support (not in SQL92 reserved words) /* Keywords for Postgres support (not in SQL92 reserved words)
* *
...@@ -307,17 +309,20 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -307,17 +309,20 @@ Oid param_type(int t); /* used in parse_expr.c */
* when some sort of pg_privileges relation is introduced. * when some sort of pg_privileges relation is introduced.
* - Todd A. Brandys 1998-01-01? * - Todd A. Brandys 1998-01-01?
*/ */
%token ABORT_TRANS, AFTER, AGGREGATE, ANALYZE, BACKWARD, BEFORE, BINARY, %token ABORT_TRANS, ACCESS, AFTER, AGGREGATE, ANALYZE,
BACKWARD, BEFORE, BINARY,
CACHE, CLUSTER, COPY, CREATEDB, CREATEUSER, CYCLE, CACHE, CLUSTER, COPY, CREATEDB, CREATEUSER, CYCLE,
DATABASE, DELIMITERS, DO, EACH, ENCODING, EXPLAIN, EXTEND, DATABASE, DELIMITERS, DO,
EACH, ENCODING, EXCLUSIVE, EXPLAIN, EXTEND,
FORWARD, FUNCTION, HANDLER, FORWARD, FUNCTION, HANDLER,
INCREMENT, INDEX, INHERITS, INSTEAD, ISNULL, INCREMENT, INDEX, INHERITS, INSTEAD, ISNULL,
LANCOMPILER, LIMIT, LISTEN, LOAD, LOCATION, LOCK_P, LANCOMPILER, LIMIT, LISTEN, LOAD, LOCATION, LOCK_P,
MAXVALUE, MINVALUE, MOVE, MAXVALUE, MINVALUE, MODE, MOVE,
NEW, NOCREATEDB, NOCREATEUSER, NONE, NOTHING, NOTIFY, NOTNULL, NEW, NOCREATEDB, NOCREATEUSER, NONE, NOTHING, NOTIFY, NOTNULL,
OFFSET, OIDS, OPERATOR, PASSWORD, PROCEDURAL, OFFSET, OIDS, OPERATOR, PASSWORD, PROCEDURAL,
RENAME, RESET, RETURNS, ROW, RULE, RENAME, RESET, RETURNS, ROW, RULE,
SEQUENCE, SERIAL, SETOF, SHOW, START, STATEMENT, STDIN, STDOUT, TRUSTED, SEQUENCE, SERIAL, SETOF, SHARE, SHOW, START, STATEMENT, STDIN, STDOUT,
TRUSTED,
UNLISTEN, UNTIL, VACUUM, VALID, VERBOSE, VERSION UNLISTEN, UNTIL, VACUUM, VALID, VERBOSE, VERSION
/* Special keywords, not in the query language - see the "lex" file */ /* Special keywords, not in the query language - see the "lex" file */
...@@ -557,22 +562,11 @@ VariableSetStmt: SET ColId TO var_value ...@@ -557,22 +562,11 @@ VariableSetStmt: SET ColId TO var_value
n->value = $4; n->value = $4;
$$ = (Node *) n; $$ = (Node *) n;
} }
| SET TRANSACTION ISOLATION LEVEL READ ColId | SET TRANSACTION ISOLATION LEVEL opt_level
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "XactIsoLevel";
n->value = $6;
if (strcasecmp(n->value, "COMMITTED"))
elog(ERROR,"parser: syntax error at or near \"%s\"", n->value);
$$ = (Node *) n;
}
| SET TRANSACTION ISOLATION LEVEL ColId
{ {
VariableSetStmt *n = makeNode(VariableSetStmt); VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "XactIsoLevel"; n->name = "XactIsoLevel";
n->value = $5; n->value = $5;
if (strcasecmp(n->value, "SERIALIZABLE"))
elog(ERROR,"parser: syntax error at or near \"%s\"", n->value);
$$ = (Node *) n; $$ = (Node *) n;
} }
| SET NAMES encoding | SET NAMES encoding
...@@ -588,6 +582,10 @@ VariableSetStmt: SET ColId TO var_value ...@@ -588,6 +582,10 @@ VariableSetStmt: SET ColId TO var_value
} }
; ;
opt_level: READ COMMITTED { $$ = "committed"; }
| SERIALIZABLE { $$ = "serializable"; }
;
var_value: Sconst { $$ = $1; } var_value: Sconst { $$ = $1; }
| DEFAULT { $$ = NULL; } | DEFAULT { $$ = NULL; }
; ;
...@@ -767,12 +765,26 @@ CreateStmt: CREATE OptTemp TABLE relation_name '(' OptTableElementList ')' ...@@ -767,12 +765,26 @@ CreateStmt: CREATE OptTemp TABLE relation_name '(' OptTableElementList ')'
} }
; ;
OptTemp: OptTemp: OptTempType { $$ = $1; }
TEMP { $$ = TRUE; } | OptTempScope OptTempType { $$ = $2; }
;
OptTempType: TEMP { $$ = TRUE; }
| TEMPORARY { $$ = TRUE; } | TEMPORARY { $$ = TRUE; }
| /*EMPTY*/ { $$ = FALSE; } | /*EMPTY*/ { $$ = FALSE; }
; ;
OptTempScope: GLOBAL
{
elog(ERROR, "GLOBAL TEMPORARY TABLE is not currently supported");
$$ = TRUE;
}
| LOCAL
{
$$ = FALSE;
}
;
OptTableElementList: OptTableElementList ',' OptTableElement OptTableElementList: OptTableElementList ',' OptTableElement
{ {
if ($3 != NULL) if ($3 != NULL)
...@@ -2580,78 +2592,31 @@ DeleteStmt: DELETE FROM relation_name ...@@ -2580,78 +2592,31 @@ DeleteStmt: DELETE FROM relation_name
} }
; ;
LockStmt: LOCK_P opt_table relation_name LockStmt: LOCK_P opt_table relation_name opt_lock
{
LockStmt *n = makeNode(LockStmt);
n->relname = $3;
n->mode = AccessExclusiveLock;
$$ = (Node *)n;
}
| LOCK_P opt_table relation_name IN opt_lmode ROW IDENT IDENT
{ {
LockStmt *n = makeNode(LockStmt); LockStmt *n = makeNode(LockStmt);
n->relname = $3; n->relname = $3;
if (strcasecmp($8, "MODE")) n->mode = $4;
elog(ERROR,"parser: syntax error at or near \"%s\"", $8);
if ($5 != NULL)
{
if (strcasecmp($5, "SHARE"))
elog(ERROR,"parser: syntax error at or near \"%s\"", $5);
if (strcasecmp($7, "EXCLUSIVE"))
elog(ERROR,"parser: syntax error at or near \"%s\"", $7);
n->mode = ShareRowExclusiveLock;
}
else
{
if (strcasecmp($7, "SHARE") == 0)
n->mode = RowShareLock;
else if (strcasecmp($7, "EXCLUSIVE") == 0)
n->mode = RowExclusiveLock;
else
elog(ERROR,"parser: syntax error at or near \"%s\"", $7);
}
$$ = (Node *)n; $$ = (Node *)n;
} }
| LOCK_P opt_table relation_name IN IDENT IDENT IDENT ;
{
LockStmt *n = makeNode(LockStmt);
n->relname = $3; opt_lock: lock_type MODE { $$ = $1; }
if (strcasecmp($7, "MODE")) | /*EMPTY*/ { $$ = AccessExclusiveLock; }
elog(ERROR,"parser: syntax error at or near \"%s\"", $7); ;
if (strcasecmp($5, "ACCESS"))
elog(ERROR,"parser: syntax error at or near \"%s\"", $5);
if (strcasecmp($6, "SHARE") == 0)
n->mode = AccessShareLock;
else if (strcasecmp($6, "EXCLUSIVE") == 0)
n->mode = AccessExclusiveLock;
else
elog(ERROR,"parser: syntax error at or near \"%s\"", $6);
$$ = (Node *)n;
}
| LOCK_P opt_table relation_name IN IDENT IDENT
{
LockStmt *n = makeNode(LockStmt);
n->relname = $3; lock_type: SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
if (strcasecmp($6, "MODE")) | ROW opt_lmode { $$ = ($2? RowShareLock: RowExclusiveLock); }
elog(ERROR,"parser: syntax error at or near \"%s\"", $6); | ACCESS opt_lmode { $$ = ($2? AccessShareLock: AccessExclusiveLock); }
if (strcasecmp($5, "SHARE") == 0) | opt_lmode { $$ = ($1? ShareLock: ExclusiveLock); }
n->mode = ShareLock;
else if (strcasecmp($5, "EXCLUSIVE") == 0)
n->mode = ExclusiveLock;
else
elog(ERROR,"parser: syntax error at or near \"%s\"", $5);
$$ = (Node *)n;
}
; ;
opt_lmode: IDENT { $$ = $1; } opt_lmode: SHARE { $$ = TRUE; }
| /*EMPTY*/ { $$ = NULL; } | EXCLUSIVE { $$ = FALSE; }
; ;
/***************************************************************************** /*****************************************************************************
* *
* QUERY: * QUERY:
...@@ -5173,12 +5138,14 @@ TypeId: ColId ...@@ -5173,12 +5138,14 @@ TypeId: ColId
ColId: IDENT { $$ = $1; } ColId: IDENT { $$ = $1; }
| datetime { $$ = $1; } | datetime { $$ = $1; }
| ABSOLUTE { $$ = "absolute"; } | ABSOLUTE { $$ = "absolute"; }
| ACCESS { $$ = "access"; }
| ACTION { $$ = "action"; } | ACTION { $$ = "action"; }
| AFTER { $$ = "after"; } | AFTER { $$ = "after"; }
| AGGREGATE { $$ = "aggregate"; } | AGGREGATE { $$ = "aggregate"; }
| BACKWARD { $$ = "backward"; } | BACKWARD { $$ = "backward"; }
| BEFORE { $$ = "before"; } | BEFORE { $$ = "before"; }
| CACHE { $$ = "cache"; } | CACHE { $$ = "cache"; }
| COMMITTED { $$ = "committed"; }
| CREATEDB { $$ = "createdb"; } | CREATEDB { $$ = "createdb"; }
| CREATEUSER { $$ = "createuser"; } | CREATEUSER { $$ = "createuser"; }
| CYCLE { $$ = "cycle"; } | CYCLE { $$ = "cycle"; }
...@@ -5187,6 +5154,7 @@ ColId: IDENT { $$ = $1; } ...@@ -5187,6 +5154,7 @@ ColId: IDENT { $$ = $1; }
| DOUBLE { $$ = "double"; } | DOUBLE { $$ = "double"; }
| EACH { $$ = "each"; } | EACH { $$ = "each"; }
| ENCODING { $$ = "encoding"; } | ENCODING { $$ = "encoding"; }
| EXCLUSIVE { $$ = "exclusive"; }
| FORWARD { $$ = "forward"; } | FORWARD { $$ = "forward"; }
| FUNCTION { $$ = "function"; } | FUNCTION { $$ = "function"; }
| HANDLER { $$ = "handler"; } | HANDLER { $$ = "handler"; }
...@@ -5203,6 +5171,7 @@ ColId: IDENT { $$ = $1; } ...@@ -5203,6 +5171,7 @@ ColId: IDENT { $$ = $1; }
| MATCH { $$ = "match"; } | MATCH { $$ = "match"; }
| MAXVALUE { $$ = "maxvalue"; } | MAXVALUE { $$ = "maxvalue"; }
| MINVALUE { $$ = "minvalue"; } | MINVALUE { $$ = "minvalue"; }
| MODE { $$ = "mode"; }
| NEXT { $$ = "next"; } | NEXT { $$ = "next"; }
| NOCREATEDB { $$ = "nocreatedb"; } | NOCREATEDB { $$ = "nocreatedb"; }
| NOCREATEUSER { $$ = "nocreateuser"; } | NOCREATEUSER { $$ = "nocreateuser"; }
...@@ -5226,6 +5195,8 @@ ColId: IDENT { $$ = $1; } ...@@ -5226,6 +5195,8 @@ ColId: IDENT { $$ = $1; }
| SCROLL { $$ = "scroll"; } | SCROLL { $$ = "scroll"; }
| SEQUENCE { $$ = "sequence"; } | SEQUENCE { $$ = "sequence"; }
| SERIAL { $$ = "serial"; } | SERIAL { $$ = "serial"; }
| SERIALIZABLE { $$ = "serializable"; }
| SHARE { $$ = "share"; }
| START { $$ = "start"; } | START { $$ = "start"; }
| STATEMENT { $$ = "statement"; } | STATEMENT { $$ = "statement"; }
| STDIN { $$ = "stdin"; } | STDIN { $$ = "stdin"; }
...@@ -5269,9 +5240,11 @@ ColLabel: ColId { $$ = $1; } ...@@ -5269,9 +5240,11 @@ ColLabel: ColId { $$ = $1; }
| EXTEND { $$ = "extend"; } | EXTEND { $$ = "extend"; }
| FALSE_P { $$ = "false"; } | FALSE_P { $$ = "false"; }
| FOREIGN { $$ = "foreign"; } | FOREIGN { $$ = "foreign"; }
| GLOBAL { $$ = "global"; }
| GROUP { $$ = "group"; } | GROUP { $$ = "group"; }
| LISTEN { $$ = "listen"; } | LISTEN { $$ = "listen"; }
| LOAD { $$ = "load"; } | LOAD { $$ = "load"; }
| LOCAL { $$ = "local"; }
| LOCK_P { $$ = "lock"; } | LOCK_P { $$ = "lock"; }
| MOVE { $$ = "move"; } | MOVE { $$ = "move"; }
| NEW { $$ = "new"; } | NEW { $$ = "new"; }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.56 1999/04/19 16:00:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.57 1999/05/12 07:22:52 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,6 +31,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -31,6 +31,7 @@ static ScanKeyword ScanKeywords[] = {
/* name, value */ /* name, value */
{"abort", ABORT_TRANS}, {"abort", ABORT_TRANS},
{"absolute", ABSOLUTE}, {"absolute", ABSOLUTE},
{"access", ACCESS},
{"action", ACTION}, {"action", ACTION},
{"add", ADD}, {"add", ADD},
{"after", AFTER}, {"after", AFTER},
...@@ -62,6 +63,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -62,6 +63,7 @@ static ScanKeyword ScanKeywords[] = {
{"collate", COLLATE}, {"collate", COLLATE},
{"column", COLUMN}, {"column", COLUMN},
{"commit", COMMIT}, {"commit", COMMIT},
{"committed", COMMITTED},
{"constraint", CONSTRAINT}, {"constraint", CONSTRAINT},
{"copy", COPY}, {"copy", COPY},
{"create", CREATE}, {"create", CREATE},
...@@ -92,7 +94,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -92,7 +94,7 @@ static ScanKeyword ScanKeywords[] = {
{"end", END_TRANS}, {"end", END_TRANS},
/***S*I***/ /***S*I***/
{"except", EXCEPT}, {"except", EXCEPT},
{"exclusive", EXCLUSIVE},
{"execute", EXECUTE}, {"execute", EXECUTE},
{"exists", EXISTS}, {"exists", EXISTS},
{"explain", EXPLAIN}, {"explain", EXPLAIN},
...@@ -107,6 +109,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -107,6 +109,7 @@ static ScanKeyword ScanKeywords[] = {
{"from", FROM}, {"from", FROM},
{"full", FULL}, {"full", FULL},
{"function", FUNCTION}, {"function", FUNCTION},
{"global", GLOBAL},
{"grant", GRANT}, {"grant", GRANT},
{"group", GROUP}, {"group", GROUP},
{"handler", HANDLER}, {"handler", HANDLER},
...@@ -122,7 +125,6 @@ static ScanKeyword ScanKeywords[] = { ...@@ -122,7 +125,6 @@ static ScanKeyword ScanKeywords[] = {
{"instead", INSTEAD}, {"instead", INSTEAD},
/***S*I***/ /***S*I***/
{"intersect", INTERSECT}, {"intersect", INTERSECT},
{"interval", INTERVAL}, {"interval", INTERVAL},
{"into", INTO}, {"into", INTO},
{"is", IS}, {"is", IS},
...@@ -146,6 +148,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -146,6 +148,7 @@ static ScanKeyword ScanKeywords[] = {
{"maxvalue", MAXVALUE}, {"maxvalue", MAXVALUE},
{"minute", MINUTE_P}, {"minute", MINUTE_P},
{"minvalue", MINVALUE}, {"minvalue", MINVALUE},
{"mode", MODE},
{"month", MONTH_P}, {"month", MONTH_P},
{"move", MOVE}, {"move", MOVE},
{"names", NAMES}, {"names", NAMES},
...@@ -202,8 +205,10 @@ static ScanKeyword ScanKeywords[] = { ...@@ -202,8 +205,10 @@ static ScanKeyword ScanKeywords[] = {
{"select", SELECT}, {"select", SELECT},
{"sequence", SEQUENCE}, {"sequence", SEQUENCE},
{"serial", SERIAL}, {"serial", SERIAL},
{"serializable", SERIALIZABLE},
{"set", SET}, {"set", SET},
{"setof", SETOF}, {"setof", SETOF},
{"share", SHARE},
{"show", SHOW}, {"show", SHOW},
{"start", START}, {"start", START},
{"statement", STATEMENT}, {"statement", STATEMENT},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment