Skip to content

Commit f16f35a

Browse files
author
Thomas G. Lockhart
committed
Support SQL92-ish DECLARE and FETCH commands.
Adds a few new keywords, but all are allowed as column names etc.
1 parent af8e276 commit f16f35a

File tree

3 files changed

+308
-220
lines changed

3 files changed

+308
-220
lines changed

src/backend/parser/gram.y

Lines changed: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* 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 $
1414
*
1515
* HISTORY
1616
* AUTHOR DATE MAJOR EVENT
@@ -185,6 +185,7 @@ Oid param_type(int t); /* used in parse_expr.c */
185185

186186
%type <boolean> opt_inh_star, opt_binary, opt_instead, opt_with_copy,
187187
index_opt_unique, opt_verbose, opt_analyze
188+
%type <boolean> cursor_clause, opt_cursor, opt_readonly, opt_of
188189

189190
%type <ival> copy_dirn, def_type, opt_direction, remove_type,
190191
opt_column, event
@@ -256,7 +257,7 @@ Oid param_type(int t); /* used in parse_expr.c */
256257
*/
257258

258259
/* 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,
260261
BEGIN_TRANS, BETWEEN, BOTH, BY,
261262
CASCADE, CAST, CHAR, CHARACTER, CHECK, CLOSE, COLLATE, COLUMN, COMMIT,
262263
CONSTRAINT, CREATE, CROSS, CURRENT, CURRENT_DATE, CURRENT_TIME,
@@ -265,14 +266,14 @@ Oid param_type(int t); /* used in parse_expr.c */
265266
END_TRANS, EXECUTE, EXISTS, EXTRACT,
266267
FETCH, FLOAT, FOR, FOREIGN, FROM, FULL,
267268
GRANT, GROUP, HAVING, HOUR_P,
268-
IN, INNER_P, INSERT, INTERVAL, INTO, IS,
269+
IN, INNER_P, INSENSITIVE, INSERT, INTERVAL, INTO, IS,
269270
JOIN, KEY, LANGUAGE, LEADING, LEFT, LIKE, LOCAL,
270271
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,
276277
TABLE, TIME, TIMESTAMP, TIMEZONE_HOUR, TIMEZONE_MINUTE,
277278
TO, TRAILING, TRANSACTION, TRIM,
278279
UNION, UNIQUE, UPDATE, USER, USING,
@@ -796,6 +797,16 @@ ColConstraint:
796797
{ $$ = $1; }
797798
;
798799

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+
*/
799810
ColConstraintElem: CHECK '(' constraint_expr ')'
800811
{
801812
Constraint *n = makeNode(Constraint);
@@ -1512,13 +1523,26 @@ DestroyStmt: DROP TABLE relation_name_list
15121523
/*****************************************************************************
15131524
*
15141525
* 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> ]
15161529
*
15171530
*****************************************************************************/
15181531

15191532
FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name
15201533
{
15211534
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+
}
15221546
n->direction = $2;
15231547
n->howMany = $3;
15241548
n->portalname = $4;
@@ -1528,6 +1552,11 @@ FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name
15281552
| MOVE opt_direction fetch_how_many opt_portal_name
15291553
{
15301554
FetchStmt *n = makeNode(FetchStmt);
1555+
if ($3 < 0)
1556+
{
1557+
$3 = -$3;
1558+
$2 = (($2 == FORWARD)? BACKWARD: FORWARD);
1559+
}
15311560
n->direction = $2;
15321561
n->howMany = $3;
15331562
n->portalname = $4;
@@ -1536,19 +1565,27 @@ FetchStmt: FETCH opt_direction fetch_how_many opt_portal_name
15361565
}
15371566
;
15381567

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 */ }
15421577
;
15431578

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; }
15471581
| ALL { $$ = 0; /* 0 means fetch all tuples*/ }
1582+
| NEXT { $$ = 1; }
1583+
| PRIOR { $$ = -1; }
15481584
| /*EMPTY*/ { $$ = 1; /*default*/ }
15491585
;
15501586

15511587
opt_portal_name: IN name { $$ = $2; }
1588+
| FROM name { $$ = $2; }
15521589
| /*EMPTY*/ { $$ = NULL; }
15531590
;
15541591

@@ -2460,11 +2497,12 @@ UpdateStmt: UPDATE relation_name
24602497
* CURSOR STATEMENTS
24612498
*
24622499
*****************************************************************************/
2463-
CursorStmt: DECLARE name opt_binary CURSOR FOR
2500+
CursorStmt: DECLARE name opt_cursor CURSOR FOR
24642501
SELECT opt_unique res_target_list2
24652502
from_clause where_clause
24662503
group_clause having_clause
24672504
union_clause sort_clause
2505+
cursor_clause
24682506
{
24692507
SelectStmt *n = makeNode(SelectStmt);
24702508

@@ -2493,6 +2531,30 @@ CursorStmt: DECLARE name opt_binary CURSOR FOR
24932531
}
24942532
;
24952533

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+
}
24962558

24972559
/*****************************************************************************
24982560
*
@@ -4551,6 +4613,7 @@ TypeId: ColId
45514613
*/
45524614
ColId: IDENT { $$ = $1; }
45534615
| datetime { $$ = $1; }
4616+
| ABSOLUTE { $$ = "absolute"; }
45544617
| ACTION { $$ = "action"; }
45554618
| CACHE { $$ = "cache"; }
45564619
| CYCLE { $$ = "cycle"; }
@@ -4562,18 +4625,26 @@ ColId: IDENT { $$ = $1; }
45624625
| FUNCTION { $$ = "function"; }
45634626
| INCREMENT { $$ = "increment"; }
45644627
| INDEX { $$ = "index"; }
4628+
| INSENSITIVE { $$ = "insensitive"; }
45654629
| KEY { $$ = "key"; }
45664630
| LANGUAGE { $$ = "language"; }
45674631
| LOCATION { $$ = "location"; }
45684632
| MATCH { $$ = "match"; }
45694633
| MAXVALUE { $$ = "maxvalue"; }
45704634
| MINVALUE { $$ = "minvalue"; }
4635+
| NEXT { $$ = "next"; }
4636+
| OF { $$ = "of"; }
4637+
| ONLY { $$ = "only"; }
45714638
| OPERATOR { $$ = "operator"; }
45724639
| OPTION { $$ = "option"; }
45734640
| PASSWORD { $$ = "password"; }
4641+
| PRIOR { $$ = "prior"; }
45744642
| PRIVILEGES { $$ = "privileges"; }
4643+
| READ { $$ = "read"; }
45754644
| RECIPE { $$ = "recipe"; }
4645+
| RELATIVE { $$ = "relative"; }
45764646
| ROW { $$ = "row"; }
4647+
| SCROLL { $$ = "scroll"; }
45774648
| SERIAL { $$ = "serial"; }
45784649
| START { $$ = "start"; }
45794650
| STATEMENT { $$ = "statement"; }

src/backend/parser/keywords.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.44 1998/09/01 04:30:23 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.45 1998/09/13 04:19:31 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -28,8 +28,9 @@
2828
* search is used to locate entries.
2929
*/
3030
static ScanKeyword ScanKeywords[] = {
31-
/* name value */
31+
/* name, value */
3232
{"abort", ABORT_TRANS},
33+
{"absolute", ABSOLUTE},
3334
{"action", ACTION},
3435
{"add", ADD},
3536
{"after", AFTER},
@@ -143,6 +144,7 @@ static ScanKeyword ScanKeywords[] = {
143144
{"natural", NATURAL},
144145
{"nchar", NCHAR},
145146
{"new", NEW},
147+
{"next", NEXT},
146148
{"no", NO},
147149
{"nocreatedb", NOCREATEDB},
148150
{"nocreateuser", NOCREATEUSER},
@@ -153,9 +155,11 @@ static ScanKeyword ScanKeywords[] = {
153155
{"notnull", NOTNULL},
154156
{"null", NULL_P},
155157
{"numeric", NUMERIC},
158+
{"of", OF},
156159
{"oids", OIDS},
157160
{"old", CURRENT},
158161
{"on", ON},
162+
{"only", ONLY},
159163
{"operator", OPERATOR},
160164
{"option", OPTION},
161165
{"or", OR},
@@ -166,12 +170,15 @@ static ScanKeyword ScanKeywords[] = {
166170
{"position", POSITION},
167171
{"precision", PRECISION},
168172
{"primary", PRIMARY},
173+
{"prior", PRIOR},
169174
{"privileges", PRIVILEGES},
170175
{"procedural", PROCEDURAL},
171176
{"procedure", PROCEDURE},
172177
{"public", PUBLIC},
178+
{"read", READ},
173179
{"recipe", RECIPE},
174180
{"references", REFERENCES},
181+
{"relative", RELATIVE},
175182
{"rename", RENAME},
176183
{"reset", RESET},
177184
{"returns", RETURNS},
@@ -180,6 +187,7 @@ static ScanKeyword ScanKeywords[] = {
180187
{"rollback", ROLLBACK},
181188
{"row", ROW},
182189
{"rule", RULE},
190+
{"scroll", SCROLL},
183191
{"second", SECOND_P},
184192
{"select", SELECT},
185193
{"sequence", SEQUENCE},

0 commit comments

Comments
 (0)