Tom Lane <[email protected]> wrote:
> Kevin Grittner <[email protected]> writes:
>> When I went to do this, I hit a shift/reduce conflict, because
>> with TABLE being optional it couldn't tell whether:
>
>> TRUNCATE MATERIALIZED VIEW x, y, z;
>
>> ... was looking for five relations or three. That goes away
>> with MATERIALIZED escalated to TYPE_FUNC_NAME_KEYWORD. Is that
>> OK?
>
> Not really. I would much rather see us not bother with this
> pedantic syntax than introduce an even-partially-reserved word.
I'm not sure it's worth it either; but two people requested it and
I didn't forsee this shift/reduce conflict, so I took a shot at it.
If we can't eliminate the conflict, I'm fine with leaving things
as they are in the latest posted patch.
> Having said that, I don't think I believe your analysis of why
> this doesn't work. The presence or absence of commas ought to
> make the syntax non-ambiguous, I would think. Maybe you just
> factored the grammar wrong.
Well, it wouldn't be the first time you've seen a better way to do
something in flex than I was able to see. Taking just the gram.y
part of the change which implemented this, and omitting the change
in reservedness of MATERIALIZED, I have:
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 820cb41..1d393c5 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -394,6 +394,7 @@ static Node *makeRecursiveViewSelect(char *relname, List
*aliases, Node *query);
%type <ival> opt_column event cursor_options opt_hold opt_set_data
%type <objtype> reindex_type drop_type comment_type security_label_type
+ trunc_type
%type <node> fetch_args limit_clause select_limit_value
offset_clause select_offset_value
@@ -5172,9 +5173,10 @@ attrs: '.' attr_name
*****************************************************************************/
TruncateStmt:
- TRUNCATE opt_table relation_expr_list opt_restart_seqs
opt_drop_behavior
+ TRUNCATE trunc_type relation_expr_list opt_restart_seqs
opt_drop_behavior
{
TruncateStmt *n = makeNode(TruncateStmt);
+ n->objtype = $2;
n->relations = $3;
n->restart_seqs = $4;
n->behavior = $5;
@@ -5182,6 +5184,12 @@ TruncateStmt:
}
;
+trunc_type:
+ TABLE { $$ = OBJECT_TABLE; }
+ | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
+ | /*EMPTY*/ { $$ = OBJECT_UNSPECIFIED; }
+ ;
+
opt_restart_seqs:
CONTINUE_P IDENTITY_P { $$ = false; }
| RESTART IDENTITY_P { $$ = true; }
I'm open to suggestions on a better way.
--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers