From f16f35a0f810f92faeead9f136b4d7c38f6eaf36 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Sun, 13 Sep 1998 04:19:33 +0000 Subject: [PATCH] Support SQL92-ish DECLARE and FETCH commands. Adds a few new keywords, but all are allowed as column names etc. --- src/backend/parser/gram.y | 103 +++++++-- src/backend/parser/keywords.c | 12 +- src/backend/parser/parse.h | 413 +++++++++++++++++----------------- 3 files changed, 308 insertions(+), 220 deletions(-) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 33bbcbb8d4..26f73a122e 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.29 1998/09/02 15:47:30 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.30 1998/09/13 04:19:29 thomas Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -185,6 +185,7 @@ Oid param_type(int t); /* used in parse_expr.c */ %type opt_inh_star, opt_binary, opt_instead, opt_with_copy, index_opt_unique, opt_verbose, opt_analyze +%type cursor_clause, opt_cursor, opt_readonly, opt_of %type copy_dirn, def_type, opt_direction, remove_type, opt_column, event @@ -256,7 +257,7 @@ Oid param_type(int t); /* used in parse_expr.c */ */ /* Keywords (in SQL92 reserved words) */ -%token ACTION, ADD, ALL, ALTER, AND, ANY AS, ASC, +%token ABSOLUTE, ACTION, ADD, ALL, ALTER, AND, ANY AS, ASC, BEGIN_TRANS, BETWEEN, BOTH, BY, CASCADE, CAST, CHAR, CHARACTER, CHECK, CLOSE, COLLATE, COLUMN, COMMIT, CONSTRAINT, CREATE, CROSS, CURRENT, CURRENT_DATE, CURRENT_TIME, @@ -265,14 +266,14 @@ Oid param_type(int t); /* used in parse_expr.c */ END_TRANS, EXECUTE, EXISTS, EXTRACT, FETCH, FLOAT, FOR, FOREIGN, FROM, FULL, GRANT, GROUP, HAVING, HOUR_P, - IN, INNER_P, INSERT, INTERVAL, INTO, IS, + IN, INNER_P, INSENSITIVE, INSERT, INTERVAL, INTO, IS, JOIN, KEY, LANGUAGE, LEADING, LEFT, LIKE, LOCAL, MATCH, MINUTE_P, MONTH_P, NAMES, - NATIONAL, NATURAL, NCHAR, NO, NOT, NOTIFY, NULL_P, NUMERIC, - ON, OPTION, OR, ORDER, OUTER_P, - PARTIAL, POSITION, PRECISION, PRIMARY, PRIVILEGES, PROCEDURE, PUBLIC, - REFERENCES, REVOKE, RIGHT, ROLLBACK, - SECOND_P, SELECT, SET, SUBSTRING, + NATIONAL, NATURAL, NCHAR, NEXT, NO, NOT, NOTIFY, NULL_P, NUMERIC, + OF, ON, ONLY, OPTION, OR, ORDER, OUTER_P, + PARTIAL, POSITION, PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE, PUBLIC, + READ, REFERENCES, RELATIVE, REVOKE, RIGHT, ROLLBACK, + SCROLL, SECOND_P, SELECT, SET, SUBSTRING, TABLE, TIME, TIMESTAMP, TIMEZONE_HOUR, TIMEZONE_MINUTE, TO, TRAILING, TRANSACTION, TRIM, UNION, UNIQUE, UPDATE, USER, USING, @@ -796,6 +797,16 @@ ColConstraint: { $$ = $1; } ; +/* The column constraint WITH NULL gives a shift/reduce error + * because it requires yacc to look more than one token ahead to + * resolve WITH TIME ZONE and WITH NULL. + * So, leave it out of the syntax for now. + | WITH NULL_P + { + $$ = NULL; + } + * - thomas 1998-09-12 + */ ColConstraintElem: CHECK '(' constraint_expr ')' { Constraint *n = makeNode(Constraint); @@ -1512,13 +1523,26 @@ DestroyStmt: DROP TABLE relation_name_list /***************************************************************************** * * QUERY: - * fetch/move [forward | backward] [number | all ] [ in ] + * fetch/move [forward | backward] [ # | all ] [ in ] + * fetch [ forward | backward | absolute | relative ] + * [ # | all | next | prior ] [ [ in | from ] ] * *****************************************************************************/ FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name { FetchStmt *n = makeNode(FetchStmt); + if ($2 == RELATIVE) + { + if ($3 == 0) + elog(ERROR,"FETCH/RELATIVE at current position is not supported"); + $2 = FORWARD; + } + if ($3 < 0) + { + $3 = -$3; + $2 = (($2 == FORWARD)? BACKWARD: FORWARD); + } n->direction = $2; n->howMany = $3; n->portalname = $4; @@ -1528,6 +1552,11 @@ FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name | MOVE opt_direction fetch_how_many opt_portal_name { FetchStmt *n = makeNode(FetchStmt); + if ($3 < 0) + { + $3 = -$3; + $2 = (($2 == FORWARD)? BACKWARD: FORWARD); + } n->direction = $2; n->howMany = $3; n->portalname = $4; @@ -1536,19 +1565,27 @@ FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name } ; -opt_direction: FORWARD { $$ = FORWARD; } - | BACKWARD { $$ = BACKWARD; } - | /*EMPTY*/ { $$ = FORWARD; /* default */ } +opt_direction: FORWARD { $$ = FORWARD; } + | BACKWARD { $$ = BACKWARD; } + | RELATIVE { $$ = RELATIVE; } + | ABSOLUTE + { + elog(NOTICE,"FETCH/ABSOLUTE not supported, using RELATIVE"); + $$ = RELATIVE; + } + | /*EMPTY*/ { $$ = FORWARD; /* default */ } ; -fetch_how_many: Iconst - { $$ = $1; - if ($1 <= 0) elog(ERROR,"Please specify nonnegative count for fetch"); } +fetch_how_many: Iconst { $$ = $1; } + | '-' Iconst { $$ = - $2; } | ALL { $$ = 0; /* 0 means fetch all tuples*/ } + | NEXT { $$ = 1; } + | PRIOR { $$ = -1; } | /*EMPTY*/ { $$ = 1; /*default*/ } ; opt_portal_name: IN name { $$ = $2; } + | FROM name { $$ = $2; } | /*EMPTY*/ { $$ = NULL; } ; @@ -2460,11 +2497,12 @@ UpdateStmt: UPDATE relation_name * CURSOR STATEMENTS * *****************************************************************************/ -CursorStmt: DECLARE name opt_binary CURSOR FOR +CursorStmt: DECLARE name opt_cursor CURSOR FOR SELECT opt_unique res_target_list2 from_clause where_clause group_clause having_clause union_clause sort_clause + cursor_clause { SelectStmt *n = makeNode(SelectStmt); @@ -2493,6 +2531,30 @@ CursorStmt: DECLARE name opt_binary CURSOR FOR } ; +opt_cursor: BINARY { $$ = TRUE; } + | INSENSITIVE { $$ = FALSE; } + | SCROLL { $$ = FALSE; } + | INSENSITIVE SCROLL { $$ = FALSE; } + | /*EMPTY*/ { $$ = FALSE; } + ; + +cursor_clause: FOR opt_readonly { $$ = $2; } + | /*EMPTY*/ { $$ = FALSE; } + ; + +opt_readonly: READ ONLY { $$ = TRUE; } + | UPDATE opt_of + { + elog(ERROR,"DECLARE/UPDATE not supported;" + " Cursors must be READ ONLY."); + $$ = FALSE; + } + ; + +opt_of: OF columnList + { + $$ = FALSE; + } /***************************************************************************** * @@ -4551,6 +4613,7 @@ TypeId: ColId */ ColId: IDENT { $$ = $1; } | datetime { $$ = $1; } + | ABSOLUTE { $$ = "absolute"; } | ACTION { $$ = "action"; } | CACHE { $$ = "cache"; } | CYCLE { $$ = "cycle"; } @@ -4562,18 +4625,26 @@ ColId: IDENT { $$ = $1; } | FUNCTION { $$ = "function"; } | INCREMENT { $$ = "increment"; } | INDEX { $$ = "index"; } + | INSENSITIVE { $$ = "insensitive"; } | KEY { $$ = "key"; } | LANGUAGE { $$ = "language"; } | LOCATION { $$ = "location"; } | MATCH { $$ = "match"; } | MAXVALUE { $$ = "maxvalue"; } | MINVALUE { $$ = "minvalue"; } + | NEXT { $$ = "next"; } + | OF { $$ = "of"; } + | ONLY { $$ = "only"; } | OPERATOR { $$ = "operator"; } | OPTION { $$ = "option"; } | PASSWORD { $$ = "password"; } + | PRIOR { $$ = "prior"; } | PRIVILEGES { $$ = "privileges"; } + | READ { $$ = "read"; } | RECIPE { $$ = "recipe"; } + | RELATIVE { $$ = "relative"; } | ROW { $$ = "row"; } + | SCROLL { $$ = "scroll"; } | SERIAL { $$ = "serial"; } | START { $$ = "start"; } | STATEMENT { $$ = "statement"; } diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c index 97e97d8c8b..f7927a707d 100644 --- a/src/backend/parser/keywords.c +++ b/src/backend/parser/keywords.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.44 1998/09/01 04:30:23 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.45 1998/09/13 04:19:31 thomas Exp $ * *------------------------------------------------------------------------- */ @@ -28,8 +28,9 @@ * search is used to locate entries. */ static ScanKeyword ScanKeywords[] = { - /* name value */ + /* name, value */ {"abort", ABORT_TRANS}, + {"absolute", ABSOLUTE}, {"action", ACTION}, {"add", ADD}, {"after", AFTER}, @@ -143,6 +144,7 @@ static ScanKeyword ScanKeywords[] = { {"natural", NATURAL}, {"nchar", NCHAR}, {"new", NEW}, + {"next", NEXT}, {"no", NO}, {"nocreatedb", NOCREATEDB}, {"nocreateuser", NOCREATEUSER}, @@ -153,9 +155,11 @@ static ScanKeyword ScanKeywords[] = { {"notnull", NOTNULL}, {"null", NULL_P}, {"numeric", NUMERIC}, + {"of", OF}, {"oids", OIDS}, {"old", CURRENT}, {"on", ON}, + {"only", ONLY}, {"operator", OPERATOR}, {"option", OPTION}, {"or", OR}, @@ -166,12 +170,15 @@ static ScanKeyword ScanKeywords[] = { {"position", POSITION}, {"precision", PRECISION}, {"primary", PRIMARY}, + {"prior", PRIOR}, {"privileges", PRIVILEGES}, {"procedural", PROCEDURAL}, {"procedure", PROCEDURE}, {"public", PUBLIC}, + {"read", READ}, {"recipe", RECIPE}, {"references", REFERENCES}, + {"relative", RELATIVE}, {"rename", RENAME}, {"reset", RESET}, {"returns", RETURNS}, @@ -180,6 +187,7 @@ static ScanKeyword ScanKeywords[] = { {"rollback", ROLLBACK}, {"row", ROW}, {"rule", RULE}, + {"scroll", SCROLL}, {"second", SECOND_P}, {"select", SELECT}, {"sequence", SEQUENCE}, diff --git a/src/backend/parser/parse.h b/src/backend/parser/parse.h index eb68436d4a..efdbb5ae4d 100644 --- a/src/backend/parser/parse.h +++ b/src/backend/parser/parse.h @@ -29,208 +29,217 @@ typedef union RuleStmt *rstmt; InsertStmt *astmt; } YYSTYPE; -#define ACTION 258 -#define ADD 259 -#define ALL 260 -#define ALTER 261 -#define AND 262 -#define ANY 263 -#define AS 264 -#define ASC 265 -#define BEGIN_TRANS 266 -#define BETWEEN 267 -#define BOTH 268 -#define BY 269 -#define CASCADE 270 -#define CAST 271 -#define CHAR 272 -#define CHARACTER 273 -#define CHECK 274 -#define CLOSE 275 -#define COLLATE 276 -#define COLUMN 277 -#define COMMIT 278 -#define CONSTRAINT 279 -#define CREATE 280 -#define CROSS 281 -#define CURRENT 282 -#define CURRENT_DATE 283 -#define CURRENT_TIME 284 -#define CURRENT_TIMESTAMP 285 -#define CURRENT_USER 286 -#define CURSOR 287 -#define DAY_P 288 -#define DECIMAL 289 -#define DECLARE 290 -#define DEFAULT 291 -#define DELETE 292 -#define DESC 293 -#define DISTINCT 294 -#define DOUBLE 295 -#define DROP 296 -#define END_TRANS 297 -#define EXECUTE 298 -#define EXISTS 299 -#define EXTRACT 300 -#define FETCH 301 -#define FLOAT 302 -#define FOR 303 -#define FOREIGN 304 -#define FROM 305 -#define FULL 306 -#define GRANT 307 -#define GROUP 308 -#define HAVING 309 -#define HOUR_P 310 -#define IN 311 -#define INNER_P 312 -#define INSERT 313 -#define INTERVAL 314 -#define INTO 315 -#define IS 316 -#define JOIN 317 -#define KEY 318 -#define LANGUAGE 319 -#define LEADING 320 -#define LEFT 321 -#define LIKE 322 -#define LOCAL 323 -#define MATCH 324 -#define MINUTE_P 325 -#define MONTH_P 326 -#define NAMES 327 -#define NATIONAL 328 -#define NATURAL 329 -#define NCHAR 330 -#define NO 331 -#define NOT 332 -#define NOTIFY 333 -#define NULL_P 334 -#define NUMERIC 335 -#define ON 336 -#define OPTION 337 -#define OR 338 -#define ORDER 339 -#define OUTER_P 340 -#define PARTIAL 341 -#define POSITION 342 -#define PRECISION 343 -#define PRIMARY 344 -#define PRIVILEGES 345 -#define PROCEDURE 346 -#define PUBLIC 347 -#define REFERENCES 348 -#define REVOKE 349 -#define RIGHT 350 -#define ROLLBACK 351 -#define SECOND_P 352 -#define SELECT 353 -#define SET 354 -#define SUBSTRING 355 -#define TABLE 356 -#define TIME 357 -#define TIMESTAMP 358 -#define TIMEZONE_HOUR 359 -#define TIMEZONE_MINUTE 360 -#define TO 361 -#define TRAILING 362 -#define TRANSACTION 363 -#define TRIM 364 -#define UNION 365 -#define UNIQUE 366 -#define UPDATE 367 -#define USER 368 -#define USING 369 -#define VALUES 370 -#define VARCHAR 371 -#define VARYING 372 -#define VIEW 373 -#define WHERE 374 -#define WITH 375 -#define WORK 376 -#define YEAR_P 377 -#define ZONE 378 -#define FALSE_P 379 -#define TRIGGER 380 -#define TRUE_P 381 -#define TYPE_P 382 -#define ABORT_TRANS 383 -#define AFTER 384 -#define AGGREGATE 385 -#define ANALYZE 386 -#define BACKWARD 387 -#define BEFORE 388 -#define BINARY 389 -#define CACHE 390 -#define CLUSTER 391 -#define COPY 392 -#define CYCLE 393 -#define DATABASE 394 -#define DELIMITERS 395 -#define DO 396 -#define EACH 397 -#define EXPLAIN 398 -#define EXTEND 399 -#define FORWARD 400 -#define FUNCTION 401 -#define HANDLER 402 -#define INCREMENT 403 -#define INDEX 404 -#define INHERITS 405 -#define INSTEAD 406 -#define ISNULL 407 -#define LANCOMPILER 408 -#define LISTEN 409 -#define LOAD 410 -#define LOCK_P 411 -#define LOCATION 412 -#define MAXVALUE 413 -#define MINVALUE 414 -#define MOVE 415 -#define NEW 416 -#define NONE 417 -#define NOTHING 418 -#define NOTNULL 419 -#define OIDS 420 -#define OPERATOR 421 -#define PROCEDURAL 422 -#define RECIPE 423 -#define RENAME 424 -#define RESET 425 -#define RETURNS 426 -#define ROW 427 -#define RULE 428 -#define SEQUENCE 429 -#define SERIAL 430 -#define SETOF 431 -#define SHOW 432 -#define START 433 -#define STATEMENT 434 -#define STDIN 435 -#define STDOUT 436 -#define TRUSTED 437 -#define VACUUM 438 -#define VERBOSE 439 -#define VERSION 440 -#define ENCODING 441 -#define UNLISTEN 442 -#define ARCHIVE 443 -#define PASSWORD 444 -#define CREATEDB 445 -#define NOCREATEDB 446 -#define CREATEUSER 447 -#define NOCREATEUSER 448 -#define VALID 449 -#define UNTIL 450 -#define IDENT 451 -#define SCONST 452 -#define Op 453 -#define ICONST 454 -#define PARAM 455 -#define FCONST 456 -#define OP 457 -#define UMINUS 458 -#define TYPECAST 459 +#define ABSOLUTE 258 +#define ACTION 259 +#define ADD 260 +#define ALL 261 +#define ALTER 262 +#define AND 263 +#define ANY 264 +#define AS 265 +#define ASC 266 +#define BEGIN_TRANS 267 +#define BETWEEN 268 +#define BOTH 269 +#define BY 270 +#define CASCADE 271 +#define CAST 272 +#define CHAR 273 +#define CHARACTER 274 +#define CHECK 275 +#define CLOSE 276 +#define COLLATE 277 +#define COLUMN 278 +#define COMMIT 279 +#define CONSTRAINT 280 +#define CREATE 281 +#define CROSS 282 +#define CURRENT 283 +#define CURRENT_DATE 284 +#define CURRENT_TIME 285 +#define CURRENT_TIMESTAMP 286 +#define CURRENT_USER 287 +#define CURSOR 288 +#define DAY_P 289 +#define DECIMAL 290 +#define DECLARE 291 +#define DEFAULT 292 +#define DELETE 293 +#define DESC 294 +#define DISTINCT 295 +#define DOUBLE 296 +#define DROP 297 +#define END_TRANS 298 +#define EXECUTE 299 +#define EXISTS 300 +#define EXTRACT 301 +#define FETCH 302 +#define FLOAT 303 +#define FOR 304 +#define FOREIGN 305 +#define FROM 306 +#define FULL 307 +#define GRANT 308 +#define GROUP 309 +#define HAVING 310 +#define HOUR_P 311 +#define IN 312 +#define INNER_P 313 +#define INSENSITIVE 314 +#define INSERT 315 +#define INTERVAL 316 +#define INTO 317 +#define IS 318 +#define JOIN 319 +#define KEY 320 +#define LANGUAGE 321 +#define LEADING 322 +#define LEFT 323 +#define LIKE 324 +#define LOCAL 325 +#define MATCH 326 +#define MINUTE_P 327 +#define MONTH_P 328 +#define NAMES 329 +#define NATIONAL 330 +#define NATURAL 331 +#define NCHAR 332 +#define NEXT 333 +#define NO 334 +#define NOT 335 +#define NOTIFY 336 +#define NULL_P 337 +#define NUMERIC 338 +#define OF 339 +#define ON 340 +#define ONLY 341 +#define OPTION 342 +#define OR 343 +#define ORDER 344 +#define OUTER_P 345 +#define PARTIAL 346 +#define POSITION 347 +#define PRECISION 348 +#define PRIMARY 349 +#define PRIOR 350 +#define PRIVILEGES 351 +#define PROCEDURE 352 +#define PUBLIC 353 +#define READ 354 +#define REFERENCES 355 +#define RELATIVE 356 +#define REVOKE 357 +#define RIGHT 358 +#define ROLLBACK 359 +#define SCROLL 360 +#define SECOND_P 361 +#define SELECT 362 +#define SET 363 +#define SUBSTRING 364 +#define TABLE 365 +#define TIME 366 +#define TIMESTAMP 367 +#define TIMEZONE_HOUR 368 +#define TIMEZONE_MINUTE 369 +#define TO 370 +#define TRAILING 371 +#define TRANSACTION 372 +#define TRIM 373 +#define UNION 374 +#define UNIQUE 375 +#define UPDATE 376 +#define USER 377 +#define USING 378 +#define VALUES 379 +#define VARCHAR 380 +#define VARYING 381 +#define VIEW 382 +#define WHERE 383 +#define WITH 384 +#define WORK 385 +#define YEAR_P 386 +#define ZONE 387 +#define FALSE_P 388 +#define TRIGGER 389 +#define TRUE_P 390 +#define TYPE_P 391 +#define ABORT_TRANS 392 +#define AFTER 393 +#define AGGREGATE 394 +#define ANALYZE 395 +#define BACKWARD 396 +#define BEFORE 397 +#define BINARY 398 +#define CACHE 399 +#define CLUSTER 400 +#define COPY 401 +#define CYCLE 402 +#define DATABASE 403 +#define DELIMITERS 404 +#define DO 405 +#define EACH 406 +#define EXPLAIN 407 +#define EXTEND 408 +#define FORWARD 409 +#define FUNCTION 410 +#define HANDLER 411 +#define INCREMENT 412 +#define INDEX 413 +#define INHERITS 414 +#define INSTEAD 415 +#define ISNULL 416 +#define LANCOMPILER 417 +#define LISTEN 418 +#define LOAD 419 +#define LOCK_P 420 +#define LOCATION 421 +#define MAXVALUE 422 +#define MINVALUE 423 +#define MOVE 424 +#define NEW 425 +#define NONE 426 +#define NOTHING 427 +#define NOTNULL 428 +#define OIDS 429 +#define OPERATOR 430 +#define PROCEDURAL 431 +#define RECIPE 432 +#define RENAME 433 +#define RESET 434 +#define RETURNS 435 +#define ROW 436 +#define RULE 437 +#define SEQUENCE 438 +#define SERIAL 439 +#define SETOF 440 +#define SHOW 441 +#define START 442 +#define STATEMENT 443 +#define STDIN 444 +#define STDOUT 445 +#define TRUSTED 446 +#define VACUUM 447 +#define VERBOSE 448 +#define VERSION 449 +#define ENCODING 450 +#define UNLISTEN 451 +#define ARCHIVE 452 +#define PASSWORD 453 +#define CREATEDB 454 +#define NOCREATEDB 455 +#define CREATEUSER 456 +#define NOCREATEUSER 457 +#define VALID 458 +#define UNTIL 459 +#define IDENT 460 +#define SCONST 461 +#define Op 462 +#define ICONST 463 +#define PARAM 464 +#define FCONST 465 +#define OP 466 +#define UMINUS 467 +#define TYPECAST 468 extern YYSTYPE yylval; -- 2.40.0