help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Interesting problem with PostgreSQL grammar ...


From: Hans-Juergen Schoenig
Subject: Interesting problem with PostgreSQL grammar ...
Date: Sun, 21 Nov 2004 13:18:25 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040922

Folks,

I am currently working on some features for PostgreSQL. My target is to implement a NOWAIT clause into DELETE, UPDATE and SELECT / SELECT FOR UPDATE:

Current the syntax of SELECT looks like that:

microtec=# \h SELECT
Command:     SELECT
Description: retrieve rows from a table or view
Syntax:
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
   * | expression [ AS output_name ] [, ...]
   [ FROM from_item [, ...] ]
   [ WHERE condition ]
   [ GROUP BY expression [, ...] ]
   [ HAVING condition [, ...] ]
   [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
   [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
   [ LIMIT { count | ALL } ]
   [ OFFSET start ]
   [ FOR UPDATE [ OF table_name [, ...] ] ]

where from_item can be one of:

   [ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
   ( select ) [ AS ] alias [ ( column_alias [, ...] ) ]
function_name ( [ argument [, ...] ] ) [ AS ] alias [ ( column_alias [, ...] | column_definition [, ...] ) ]
   function_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] )
from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ]


I want to add NOWAIT to FOR UPDATE ...

   [ FOR UPDATE [ OF table_name [, ...] ]  [NOWAIT]]

I am running into shift / reduce problems when adding the NOWAIT keyword.
Here are the (to me) relevant parts of postgresql-snapshot/src/backend/parser/gram.y:

select_no_parens:
simple_select { $$ = $1; }
                       | select_clause sort_clause
                               {
insertSelectOptions((SelectStmt *) $1, $2, NIL, NULL, NULL);
                                       $$ = $1;
                               }
| select_clause opt_sort_clause for_update_clause opt_select_limit
                               {
insertSelectOptions((SelectStmt *) $1, $2, $3, list_nth($4, 0), list_nth($4, 1));
                                       $$ = $1;
                               }
| select_clause opt_sort_clause select_limit opt_for_update_clause
                               {
insertSelectOptions((SelectStmt *) $1, $2, $4, list_nth($3, 0), list_nth($3, 1));
                                       $$ = $1;
                               }
               ;


.......


for_update_clause:
FOR UPDATE update_list { $$ = $3; } | FOR READ ONLY { $$ = NULL; }
               ;
opt_for_update_clause:
for_update_clause { $$ = $1; } | /* EMPTY */ { $$ = NULL; }
               ;
update_list:
OF name_list { $$ = $2; } | /* EMPTY */ { $$ = list_make1(NULL); }
               ;


what i have tried is to add opt_nowait to "select_clause opt_sort_clause select_limit opt_for_update_clause". this will cause errors.
opt_nowait is defined as:

opt_nowait:     NOWAIT                  { $$ = TRUE; }
| /*EMPTY*/ { $$ = FALSE; }
               ;

Interestingly opt_nowait works for LOCK statements:
LockStmt:       LOCK_P opt_table qualified_name_list opt_lock opt_nowait
                               {
                                       LockStmt *n = makeNode(LockStmt);
                                       n->relations = $3;
                                       n->mode = $4;
                                       n->nowait = $5;
                                       $$ = (Node *)n;
                               }
               ;
opt_lock:       IN_P lock_type MODE                     { $$ = $2; }
| /*EMPTY*/ { $$ = AccessExclusiveLock; }
               ;
lock_type: ACCESS SHARE { $$ = AccessShareLock; } | ROW SHARE { $$ = RowShareLock; } | ROW EXCLUSIVE { $$ = RowExclusiveLock; } | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; } | SHARE { $$ = ShareLock; } | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; } | EXCLUSIVE { $$ = ExclusiveLock; } | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
               ;
opt_nowait:     NOWAIT                  { $$ = TRUE; }
| /*EMPTY*/ { $$ = FALSE; }
               ;
In this case adding opt_nowait will not cause problems at all.
Can anybody tell me why?

   Best regards,

      Hans














reply via email to

[Prev in Thread] Current Thread [Next in Thread]