@@ -291,10 +291,12 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
291
291
CreateExtensionStmt CreateFunctionStmt CreateGraphStmt
292
292
CreateTableStmt CreateTableSpaceStmt CreateFdwStmt
293
293
CreateUserStmt
294
+ DeclareCursorStmt
294
295
DefineStmt DeleteStmt DoStmt DropCastStmt DropdbStmt DropGraphStmt
295
296
DropStmt DropTableSpaceStmt DropTransformStmt DropOpClassStmt DropOpFamilyStmt
296
297
DropRoleStmt
297
298
ExplainStmt ExplainableStmt
299
+ FetchStmt
298
300
GrantStmt
299
301
IndexStmt InsertStmt
300
302
LockStmt
@@ -440,7 +442,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
440
442
441
443
%type <string> copy_file_name
442
444
access_method_clause
443
- table_access_method_clause
445
+ table_access_method_clause cursor_name
444
446
opt_index_name cluster_index_specification
445
447
446
448
%type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
@@ -469,7 +471,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
469
471
%type <defelt> createdb_opt_item
470
472
%type <string> createdb_opt_name
471
473
472
- %type <integer> event
474
+ %type <integer> event cursor_options opt_hold
473
475
%type <integer> object_type_any_name object_type_name object_type_name_on_any_name
474
476
drop_type_name
475
477
@@ -576,7 +578,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
576
578
%type <string> symbolic_name schema_name temporal_cast attr_name
577
579
%type <keyword> cypher_reserved_keyword safe_keywords conflicted_keywords
578
580
579
- %type <node> select_limit_value
581
+ %type <node> fetch_args select_limit_value
580
582
offset_clause select_offset_value
581
583
select_fetch_first_value I_or_F_const
582
584
%type <integer> row_or_rows first_or_next
@@ -926,6 +928,7 @@ stmt:
926
928
| DropTableSpaceStmt
927
929
| DropTransformStmt
928
930
| ExplainStmt
931
+ | FetchStmt
929
932
| GrantStmt
930
933
| IndexStmt
931
934
| InsertStmt
@@ -2648,6 +2651,40 @@ returning_clause:
2648
2651
;
2649
2652
2650
2653
2654
+ /* ****************************************************************************
2655
+ *
2656
+ * QUERY:
2657
+ * CURSOR STATEMENTS
2658
+ *
2659
+ *****************************************************************************/
2660
+ DeclareCursorStmt : DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
2661
+ {
2662
+ DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
2663
+ n->portalname = $2 ;
2664
+ /* currently we always set FAST_PLAN option */
2665
+ n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
2666
+ n->query = $7 ;
2667
+ $$ = (Node *)n;
2668
+ }
2669
+ ;
2670
+
2671
+ cursor_name : name { $$ = $1 ; }
2672
+ ;
2673
+
2674
+ cursor_options : /* EMPTY*/ { $$ = 0 ; }
2675
+ | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
2676
+ | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
2677
+ | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
2678
+ | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
2679
+ | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
2680
+ ;
2681
+
2682
+ opt_hold : /* EMPTY */ { $$ = 0 ; }
2683
+ | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
2684
+ | WITHOUT HOLD { $$ = 0 ; }
2685
+ ;
2686
+
2687
+
2651
2688
/* ****************************************************************************
2652
2689
*
2653
2690
* QUERY:
@@ -6243,9 +6280,9 @@ ExplainableStmt:
6243
6280
| InsertStmt
6244
6281
| UpdateStmt
6245
6282
| DeleteStmt
6246
- // | DeclareCursorStmt TODO
6283
+ | DeclareCursorStmt
6247
6284
| CreateAsStmt
6248
- //| CreateMatViewStmt
6285
+ //| CreateMatViewStmt TODO
6249
6286
//| RefreshMatViewStmt
6250
6287
//| ExecuteStmt
6251
6288
;
@@ -10326,6 +10363,165 @@ AlterDatabaseSetStmt:
10326
10363
;
10327
10364
10328
10365
10366
+ /* ****************************************************************************
10367
+ *
10368
+ * QUERY:
10369
+ * fetch/move
10370
+ *
10371
+ *****************************************************************************/
10372
+
10373
+ FetchStmt : FETCH fetch_args
10374
+ {
10375
+ FetchStmt *n = (FetchStmt *) $2 ;
10376
+ n->ismove = false ;
10377
+ $$ = (Node *)n;
10378
+ }
10379
+ | MOVE fetch_args
10380
+ {
10381
+ FetchStmt *n = (FetchStmt *) $2 ;
10382
+ n->ismove = true ;
10383
+ $$ = (Node *)n;
10384
+ }
10385
+ ;
10386
+
10387
+ fetch_args : cursor_name
10388
+ {
10389
+ FetchStmt *n = makeNode(FetchStmt);
10390
+ n->portalname = $1 ;
10391
+ n->direction = FETCH_FORWARD;
10392
+ n->howMany = 1 ;
10393
+ $$ = (Node *)n;
10394
+ }
10395
+ | from_in cursor_name
10396
+ {
10397
+ FetchStmt *n = makeNode(FetchStmt);
10398
+ n->portalname = $2 ;
10399
+ n->direction = FETCH_FORWARD;
10400
+ n->howMany = 1 ;
10401
+ $$ = (Node *)n;
10402
+ }
10403
+ | NEXT opt_from_in cursor_name
10404
+ {
10405
+ FetchStmt *n = makeNode(FetchStmt);
10406
+ n->portalname = $3 ;
10407
+ n->direction = FETCH_FORWARD;
10408
+ n->howMany = 1 ;
10409
+ $$ = (Node *)n;
10410
+ }
10411
+ | PRIOR opt_from_in cursor_name
10412
+ {
10413
+ FetchStmt *n = makeNode(FetchStmt);
10414
+ n->portalname = $3 ;
10415
+ n->direction = FETCH_BACKWARD;
10416
+ n->howMany = 1 ;
10417
+ $$ = (Node *)n;
10418
+ }
10419
+ | FIRST_P opt_from_in cursor_name
10420
+ {
10421
+ FetchStmt *n = makeNode(FetchStmt);
10422
+ n->portalname = $3 ;
10423
+ n->direction = FETCH_ABSOLUTE;
10424
+ n->howMany = 1 ;
10425
+ $$ = (Node *)n;
10426
+ }
10427
+ | LAST_P opt_from_in cursor_name
10428
+ {
10429
+ FetchStmt *n = makeNode(FetchStmt);
10430
+ n->portalname = $3 ;
10431
+ n->direction = FETCH_ABSOLUTE;
10432
+ n->howMany = -1 ;
10433
+ $$ = (Node *)n;
10434
+ }
10435
+ | ABSOLUTE_P SignedIconst opt_from_in cursor_name
10436
+ {
10437
+ FetchStmt *n = makeNode(FetchStmt);
10438
+ n->portalname = $4 ;
10439
+ n->direction = FETCH_ABSOLUTE;
10440
+ n->howMany = $2 ;
10441
+ $$ = (Node *)n;
10442
+ }
10443
+ | RELATIVE_P SignedIconst opt_from_in cursor_name
10444
+ {
10445
+ FetchStmt *n = makeNode(FetchStmt);
10446
+ n->portalname = $4 ;
10447
+ n->direction = FETCH_RELATIVE;
10448
+ n->howMany = $2 ;
10449
+ $$ = (Node *)n;
10450
+ }
10451
+ | SignedIconst opt_from_in cursor_name
10452
+ {
10453
+ FetchStmt *n = makeNode(FetchStmt);
10454
+ n->portalname = $3 ;
10455
+ n->direction = FETCH_FORWARD;
10456
+ n->howMany = $1 ;
10457
+ $$ = (Node *)n;
10458
+ }
10459
+ | ALL opt_from_in cursor_name
10460
+ {
10461
+ FetchStmt *n = makeNode(FetchStmt);
10462
+ n->portalname = $3 ;
10463
+ n->direction = FETCH_FORWARD;
10464
+ n->howMany = FETCH_ALL;
10465
+ $$ = (Node *)n;
10466
+ }
10467
+ | FORWARD opt_from_in cursor_name
10468
+ {
10469
+ FetchStmt *n = makeNode(FetchStmt);
10470
+ n->portalname = $3 ;
10471
+ n->direction = FETCH_FORWARD;
10472
+ n->howMany = 1 ;
10473
+ $$ = (Node *)n;
10474
+ }
10475
+ | FORWARD SignedIconst opt_from_in cursor_name
10476
+ {
10477
+ FetchStmt *n = makeNode(FetchStmt);
10478
+ n->portalname = $4 ;
10479
+ n->direction = FETCH_FORWARD;
10480
+ n->howMany = $2 ;
10481
+ $$ = (Node *)n;
10482
+ }
10483
+ | FORWARD ALL opt_from_in cursor_name
10484
+ {
10485
+ FetchStmt *n = makeNode(FetchStmt);
10486
+ n->portalname = $4 ;
10487
+ n->direction = FETCH_FORWARD;
10488
+ n->howMany = FETCH_ALL;
10489
+ $$ = (Node *)n;
10490
+ }
10491
+ | BACKWARD opt_from_in cursor_name
10492
+ {
10493
+ FetchStmt *n = makeNode(FetchStmt);
10494
+ n->portalname = $3 ;
10495
+ n->direction = FETCH_BACKWARD;
10496
+ n->howMany = 1 ;
10497
+ $$ = (Node *)n;
10498
+ }
10499
+ | BACKWARD SignedIconst opt_from_in cursor_name
10500
+ {
10501
+ FetchStmt *n = makeNode(FetchStmt);
10502
+ n->portalname = $4 ;
10503
+ n->direction = FETCH_BACKWARD;
10504
+ n->howMany = $2 ;
10505
+ $$ = (Node *)n;
10506
+ }
10507
+ | BACKWARD ALL opt_from_in cursor_name
10508
+ {
10509
+ FetchStmt *n = makeNode(FetchStmt);
10510
+ n->portalname = $4 ;
10511
+ n->direction = FETCH_BACKWARD;
10512
+ n->howMany = FETCH_ALL;
10513
+ $$ = (Node *)n;
10514
+ }
10515
+ ;
10516
+
10517
+ from_in : FROM
10518
+ | IN
10519
+ ;
10520
+
10521
+ opt_from_in : from_in
10522
+ | /* EMPTY */
10523
+ ;
10524
+
10329
10525
/* ****************************************************************************
10330
10526
*
10331
10527
* GRANT and REVOKE statements
0 commit comments