Skip to content

Commit d779dd3

Browse files
committed
Support Cursors
1 parent 21d0b59 commit d779dd3

File tree

1 file changed

+201
-5
lines changed

1 file changed

+201
-5
lines changed

src/backend/parser/cypher_gram.y

+201-5
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
291291
CreateExtensionStmt CreateFunctionStmt CreateGraphStmt
292292
CreateTableStmt CreateTableSpaceStmt CreateFdwStmt
293293
CreateUserStmt
294+
DeclareCursorStmt
294295
DefineStmt DeleteStmt DoStmt DropCastStmt DropdbStmt DropGraphStmt
295296
DropStmt DropTableSpaceStmt DropTransformStmt DropOpClassStmt DropOpFamilyStmt
296297
DropRoleStmt
297298
ExplainStmt ExplainableStmt
299+
FetchStmt
298300
GrantStmt
299301
IndexStmt InsertStmt
300302
LockStmt
@@ -440,7 +442,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
440442

441443
%type <string> copy_file_name
442444
access_method_clause
443-
table_access_method_clause
445+
table_access_method_clause cursor_name
444446
opt_index_name cluster_index_specification
445447

446448
%type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
@@ -469,7 +471,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
469471
%type <defelt> createdb_opt_item
470472
%type <string> createdb_opt_name
471473

472-
%type <integer> event
474+
%type <integer> event cursor_options opt_hold
473475
%type <integer> object_type_any_name object_type_name object_type_name_on_any_name
474476
drop_type_name
475477

@@ -576,7 +578,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
576578
%type <string> symbolic_name schema_name temporal_cast attr_name
577579
%type <keyword> cypher_reserved_keyword safe_keywords conflicted_keywords
578580

579-
%type <node> select_limit_value
581+
%type <node> fetch_args select_limit_value
580582
offset_clause select_offset_value
581583
select_fetch_first_value I_or_F_const
582584
%type <integer> row_or_rows first_or_next
@@ -926,6 +928,7 @@ stmt:
926928
| DropTableSpaceStmt
927929
| DropTransformStmt
928930
| ExplainStmt
931+
| FetchStmt
929932
| GrantStmt
930933
| IndexStmt
931934
| InsertStmt
@@ -2648,6 +2651,40 @@ returning_clause:
26482651
;
26492652

26502653

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+
26512688
/*****************************************************************************
26522689
*
26532690
* QUERY:
@@ -6243,9 +6280,9 @@ ExplainableStmt:
62436280
| InsertStmt
62446281
| UpdateStmt
62456282
| DeleteStmt
6246-
//| DeclareCursorStmt TODO
6283+
| DeclareCursorStmt
62476284
| CreateAsStmt
6248-
//| CreateMatViewStmt
6285+
//| CreateMatViewStmt TODO
62496286
//| RefreshMatViewStmt
62506287
//| ExecuteStmt
62516288
;
@@ -10326,6 +10363,165 @@ AlterDatabaseSetStmt:
1032610363
;
1032710364

1032810365

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+
1032910525
/*****************************************************************************
1033010526
*
1033110527
* GRANT and REVOKE statements

0 commit comments

Comments
 (0)