10
10
*
11
11
*
12
12
* IDENTIFICATION
13
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.29 1998/09/02 15:47:30 thomas Exp $
13
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.30 1998/09/13 04:19:29 thomas Exp $
14
14
*
15
15
* HISTORY
16
16
* AUTHOR DATE MAJOR EVENT
@@ -185,6 +185,7 @@ Oid param_type(int t); /* used in parse_expr.c */
185
185
186
186
%type <boolean> opt_inh_star, opt_binary, opt_instead, opt_with_copy,
187
187
index_opt_unique, opt_verbose, opt_analyze
188
+ %type <boolean> cursor_clause, opt_cursor, opt_readonly, opt_of
188
189
189
190
%type <ival> copy_dirn, def_type, opt_direction, remove_type,
190
191
opt_column, event
@@ -256,7 +257,7 @@ Oid param_type(int t); /* used in parse_expr.c */
256
257
*/
257
258
258
259
/* Keywords (in SQL92 reserved words) */
259
- %token ACTION, ADD, ALL, ALTER, AND, ANY AS, ASC,
260
+ %token ABSOLUTE, ACTION, ADD, ALL, ALTER, AND, ANY AS, ASC,
260
261
BEGIN_TRANS, BETWEEN, BOTH, BY,
261
262
CASCADE, CAST, CHAR, CHARACTER, CHECK, CLOSE, COLLATE, COLUMN, COMMIT,
262
263
CONSTRAINT, CREATE, CROSS, CURRENT, CURRENT_DATE, CURRENT_TIME,
@@ -265,14 +266,14 @@ Oid param_type(int t); /* used in parse_expr.c */
265
266
END_TRANS, EXECUTE, EXISTS, EXTRACT,
266
267
FETCH, FLOAT, FOR, FOREIGN, FROM, FULL,
267
268
GRANT, GROUP, HAVING, HOUR_P,
268
- IN, INNER_P, INSERT, INTERVAL, INTO, IS,
269
+ IN, INNER_P, INSENSITIVE, INSERT, INTERVAL, INTO, IS,
269
270
JOIN, KEY, LANGUAGE, LEADING, LEFT, LIKE, LOCAL,
270
271
MATCH, MINUTE_P, MONTH_P, NAMES,
271
- NATIONAL, NATURAL, NCHAR, NO, NOT, NOTIFY, NULL_P, NUMERIC,
272
- ON , OPTION, OR, ORDER, OUTER_P,
273
- PARTIAL, POSITION, PRECISION, PRIMARY, PRIVILEGES, PROCEDURE, PUBLIC,
274
- REFERENCES, REVOKE, RIGHT, ROLLBACK,
275
- SECOND_P, SELECT, SET, SUBSTRING,
272
+ NATIONAL, NATURAL, NCHAR, NEXT, NO, NOT, NOTIFY, NULL_P, NUMERIC,
273
+ OF, ON, ONLY , OPTION, OR, ORDER, OUTER_P,
274
+ PARTIAL, POSITION, PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE, PUBLIC,
275
+ READ, REFERENCES, RELATIVE , REVOKE, RIGHT, ROLLBACK,
276
+ SCROLL, SECOND_P, SELECT, SET, SUBSTRING,
276
277
TABLE, TIME, TIMESTAMP, TIMEZONE_HOUR, TIMEZONE_MINUTE,
277
278
TO, TRAILING, TRANSACTION, TRIM,
278
279
UNION, UNIQUE, UPDATE, USER, USING,
@@ -796,6 +797,16 @@ ColConstraint:
796
797
{ $$ = $1; }
797
798
;
798
799
800
+ /* The column constraint WITH NULL gives a shift/reduce error
801
+ * because it requires yacc to look more than one token ahead to
802
+ * resolve WITH TIME ZONE and WITH NULL.
803
+ * So, leave it out of the syntax for now.
804
+ | WITH NULL_P
805
+ {
806
+ $$ = NULL;
807
+ }
808
+ * - thomas 1998-09-12
809
+ */
799
810
ColConstraintElem: CHECK '(' constraint_expr ')'
800
811
{
801
812
Constraint *n = makeNode(Constraint);
@@ -1512,13 +1523,26 @@ DestroyStmt: DROP TABLE relation_name_list
1512
1523
/*****************************************************************************
1513
1524
*
1514
1525
* QUERY:
1515
- * fetch/move [forward | backward] [number | all ] [ in <portalname> ]
1526
+ * fetch/move [forward | backward] [ # | all ] [ in <portalname> ]
1527
+ * fetch [ forward | backward | absolute | relative ]
1528
+ * [ # | all | next | prior ] [ [ in | from ] <portalname> ]
1516
1529
*
1517
1530
*****************************************************************************/
1518
1531
1519
1532
FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name
1520
1533
{
1521
1534
FetchStmt *n = makeNode(FetchStmt);
1535
+ if ($2 == RELATIVE)
1536
+ {
1537
+ if ($3 == 0)
1538
+ elog(ERROR,"FETCH/RELATIVE at current position is not supported");
1539
+ $2 = FORWARD;
1540
+ }
1541
+ if ($3 < 0)
1542
+ {
1543
+ $3 = -$3;
1544
+ $2 = (($2 == FORWARD)? BACKWARD: FORWARD);
1545
+ }
1522
1546
n->direction = $2;
1523
1547
n->howMany = $3;
1524
1548
n->portalname = $4;
@@ -1528,6 +1552,11 @@ FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name
1528
1552
| MOVE opt_direction fetch_how_many opt_portal_name
1529
1553
{
1530
1554
FetchStmt *n = makeNode(FetchStmt);
1555
+ if ($3 < 0)
1556
+ {
1557
+ $3 = -$3;
1558
+ $2 = (($2 == FORWARD)? BACKWARD: FORWARD);
1559
+ }
1531
1560
n->direction = $2;
1532
1561
n->howMany = $3;
1533
1562
n->portalname = $4;
@@ -1536,19 +1565,27 @@ FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name
1536
1565
}
1537
1566
;
1538
1567
1539
- opt_direction: FORWARD { $$ = FORWARD; }
1540
- | BACKWARD { $$ = BACKWARD; }
1541
- | /*EMPTY*/ { $$ = FORWARD; /* default */ }
1568
+ opt_direction: FORWARD { $$ = FORWARD; }
1569
+ | BACKWARD { $$ = BACKWARD; }
1570
+ | RELATIVE { $$ = RELATIVE; }
1571
+ | ABSOLUTE
1572
+ {
1573
+ elog(NOTICE,"FETCH/ABSOLUTE not supported, using RELATIVE");
1574
+ $$ = RELATIVE;
1575
+ }
1576
+ | /*EMPTY*/ { $$ = FORWARD; /* default */ }
1542
1577
;
1543
1578
1544
- fetch_how_many: Iconst
1545
- { $$ = $1;
1546
- if ($1 <= 0) elog(ERROR,"Please specify nonnegative count for fetch"); }
1579
+ fetch_how_many: Iconst { $$ = $1; }
1580
+ | '-' Iconst { $$ = - $2; }
1547
1581
| ALL { $$ = 0; /* 0 means fetch all tuples*/ }
1582
+ | NEXT { $$ = 1; }
1583
+ | PRIOR { $$ = -1; }
1548
1584
| /*EMPTY*/ { $$ = 1; /*default*/ }
1549
1585
;
1550
1586
1551
1587
opt_portal_name: IN name { $$ = $2; }
1588
+ | FROM name { $$ = $2; }
1552
1589
| /*EMPTY*/ { $$ = NULL; }
1553
1590
;
1554
1591
@@ -2460,11 +2497,12 @@ UpdateStmt: UPDATE relation_name
2460
2497
* CURSOR STATEMENTS
2461
2498
*
2462
2499
*****************************************************************************/
2463
- CursorStmt: DECLARE name opt_binary CURSOR FOR
2500
+ CursorStmt: DECLARE name opt_cursor CURSOR FOR
2464
2501
SELECT opt_unique res_target_list2
2465
2502
from_clause where_clause
2466
2503
group_clause having_clause
2467
2504
union_clause sort_clause
2505
+ cursor_clause
2468
2506
{
2469
2507
SelectStmt *n = makeNode(SelectStmt);
2470
2508
@@ -2493,6 +2531,30 @@ CursorStmt: DECLARE name opt_binary CURSOR FOR
2493
2531
}
2494
2532
;
2495
2533
2534
+ opt_cursor: BINARY { $$ = TRUE; }
2535
+ | INSENSITIVE { $$ = FALSE; }
2536
+ | SCROLL { $$ = FALSE; }
2537
+ | INSENSITIVE SCROLL { $$ = FALSE; }
2538
+ | /*EMPTY*/ { $$ = FALSE; }
2539
+ ;
2540
+
2541
+ cursor_clause: FOR opt_readonly { $$ = $2; }
2542
+ | /*EMPTY*/ { $$ = FALSE; }
2543
+ ;
2544
+
2545
+ opt_readonly: READ ONLY { $$ = TRUE; }
2546
+ | UPDATE opt_of
2547
+ {
2548
+ elog(ERROR,"DECLARE/UPDATE not supported;"
2549
+ " Cursors must be READ ONLY.");
2550
+ $$ = FALSE;
2551
+ }
2552
+ ;
2553
+
2554
+ opt_of: OF columnList
2555
+ {
2556
+ $$ = FALSE;
2557
+ }
2496
2558
2497
2559
/*****************************************************************************
2498
2560
*
@@ -4551,6 +4613,7 @@ TypeId: ColId
4551
4613
*/
4552
4614
ColId: IDENT { $$ = $1; }
4553
4615
| datetime { $$ = $1; }
4616
+ | ABSOLUTE { $$ = "absolute"; }
4554
4617
| ACTION { $$ = "action"; }
4555
4618
| CACHE { $$ = "cache"; }
4556
4619
| CYCLE { $$ = "cycle"; }
@@ -4562,18 +4625,26 @@ ColId: IDENT { $$ = $1; }
4562
4625
| FUNCTION { $$ = "function"; }
4563
4626
| INCREMENT { $$ = "increment"; }
4564
4627
| INDEX { $$ = "index"; }
4628
+ | INSENSITIVE { $$ = "insensitive"; }
4565
4629
| KEY { $$ = "key"; }
4566
4630
| LANGUAGE { $$ = "language"; }
4567
4631
| LOCATION { $$ = "location"; }
4568
4632
| MATCH { $$ = "match"; }
4569
4633
| MAXVALUE { $$ = "maxvalue"; }
4570
4634
| MINVALUE { $$ = "minvalue"; }
4635
+ | NEXT { $$ = "next"; }
4636
+ | OF { $$ = "of"; }
4637
+ | ONLY { $$ = "only"; }
4571
4638
| OPERATOR { $$ = "operator"; }
4572
4639
| OPTION { $$ = "option"; }
4573
4640
| PASSWORD { $$ = "password"; }
4641
+ | PRIOR { $$ = "prior"; }
4574
4642
| PRIVILEGES { $$ = "privileges"; }
4643
+ | READ { $$ = "read"; }
4575
4644
| RECIPE { $$ = "recipe"; }
4645
+ | RELATIVE { $$ = "relative"; }
4576
4646
| ROW { $$ = "row"; }
4647
+ | SCROLL { $$ = "scroll"; }
4577
4648
| SERIAL { $$ = "serial"; }
4578
4649
| START { $$ = "start"; }
4579
4650
| STATEMENT { $$ = "statement"; }
0 commit comments