@@ -294,7 +294,7 @@ make_name(void)
294294%type <str> opt_indirection expr_list extract_list extract_arg
295295%type <str> position_list substr_list substr_from alter_column_action
296296%type <str> trim_list in_expr substr_for attr attrs drop_behavior
297- %type <str> Typename SimpleTypename GenericType Numeric opt_float opt_numeric
297+ %type <str> Typename SimpleTypename Generic Numeric generic opt_float opt_numeric
298298%type <str> opt_decimal Character character opt_varying opt_charset
299299%type <str> opt_collate datetime opt_timezone opt_interval table_ref
300300%type <str> row_expr row_descriptor row_list ConstDatetime opt_chain
@@ -313,7 +313,7 @@ make_name(void)
313313%type <str> index_list func_index index_elem opt_class access_method_clause
314314%type <str> index_opt_unique IndexStmt func_return ConstInterval
315315%type <str> func_args_list func_args opt_with ProcedureStmt def_arg
316- %type <str> def_elem def_list definition DefineStmt
316+ %type <str> def_elem def_list definition DefineStmt select_with_parens
317317%type <str> opt_instead event event_object RuleActionList opt_using
318318%type <str> RuleActionStmtOrEmpty RuleActionMulti func_as reindex_type
319319%type <str> RuleStmt opt_column opt_name oper_argtypes sysid_clause
@@ -2066,16 +2066,7 @@ RuleActionMulti: RuleActionMulti ';' RuleActionStmtOrEmpty
20662066{$$ = cat2_str($1 , make_str(" ;" )); }
20672067;
20682068
2069- /*
2070- * Allowing RuleActionStmt to be a SelectStmt creates an ambiguity:
2071- * is the RuleActionList "((SELECT foo))" a standalone RuleActionStmt,
2072- * or a one-entry RuleActionMulti list? We don't really care, but yacc
2073- * wants to know. We use operator precedence to resolve the ambiguity:
2074- * giving this rule a higher precedence than ')' will force a reduce
2075- * rather than shift decision, causing the one-entry-list interpretation
2076- * to be chosen.
2077- */
2078- RuleActionStmt :SelectStmt %prec TYPECAST
2069+ RuleActionStmt :SelectStmt
20792070| InsertStmt
20802071| UpdateStmt
20812072| DeleteStmt
@@ -2491,11 +2482,17 @@ opt_cursor: BINARY { $$ = make_str("binary"); }
24912482 *
24922483 *****************************************************************************/
24932484
2494- SelectStmt :select_no_parens %prec TYPECAST
2485+ SelectStmt :select_no_parens %prec UMINUS
2486+ {$$ =$1 ; }
2487+ | select_with_parens %prec UMINUS
2488+ {$$ =$1 ; }
2489+ ;
2490+
2491+ select_with_parens :' (' select_no_parens ' )'
24952492 {
2496- $$ =$1 ;
2493+ $$ =cat_str( 3 , make_str( " ( " ), $2 , make_str( " ) " )) ;
24972494 }
2498- | ' (' SelectStmt ' )'
2495+ | ' (' select_with_parens ' )'
24992496 {
25002497$$ = cat_str(3 , make_str(" (" ),$2 , make_str(" )" ));
25012498 }
@@ -2524,9 +2521,9 @@ select_clause: simple_select
25242521$$ =$1 ;
25252522
25262523 }
2527- | ' ( ' SelectStmt ' ) '
2524+ | select_with_parens
25282525 {
2529- $$ =cat_str( 3 , make_str( " ( " ), $2 , make_str( " ) " )) ;
2526+ $$ =$1 ;
25302527 }
25312528;
25322529
@@ -2745,10 +2742,6 @@ from_list: from_list ',' table_ref{ $$ = cat_str(3, $1, make_str(","), $3); }
27452742 * between table_ref := '(' joined_table ')' alias_clause
27462743 * and joined_table := '(' joined_table ')'. So, we must have the
27472744 * redundant-looking productions here instead.
2748- *
2749- * Note that the SQL spec does not permit a subselect (<derived_table>)
2750- * without an alias clause, so we don't either. This avoids the problem
2751- * of needing to invent a refname for an unlabeled subselect.
27522745*/
27532746table_ref :relation_expr
27542747 {
@@ -2758,9 +2751,13 @@ table_ref: relation_expr
27582751{
27592752$$ = cat2_str($1 ,$2 );
27602753}
2761- | ' (' SelectStmt ' )' alias_clause
2754+ | select_with_parens
2755+ {
2756+ mmerror (ET_ERROR," sub-SELECT in FROM must have an alias" );
2757+ }
2758+ | select_with_parens alias_clause
27622759{
2763- $$ =cat_str( 4 , make_str( " ( " ), $2 , make_str( " ) " ), $4 );
2760+ $$ =cat2_str( $1 , $2 );
27642761}
27652762| joined_table
27662763{
@@ -2856,12 +2853,12 @@ relation_expr:relation_name
28562853/* normal relations*/
28572854$$ =$1 ;
28582855}
2859- | relation_name ' *' % prec ' = '
2856+ | relation_name ' *'
28602857{
28612858/* inheritance query*/
28622859$$ = cat2_str($1 , make_str(" *" ));
28632860}
2864- | ONLY relation_name % prec ' = '
2861+ | ONLY relation_name
28652862{
28662863/* inheritance query*/
28672864$$ = cat2_str(make_str(" ONLY" ),$2 );
@@ -2928,15 +2925,22 @@ SimpleTypename: ConstTypename{ $$ = $1; }
29282925| ConstInterval {$$ =$1 ; }
29292926 ;
29302927
2931- ConstTypename :GenericType {$$ =$1 ; }
2928+ ConstTypename :Generic {$$ =$1 ; }
29322929| ConstDatetime {$$ =$1 ; }
29332930| Numeric {$$ =$1 ; }
29342931| Geometric {$$ =$1 ; }
29352932| Bit {$$ =$1 ; }
29362933| Character {$$ =$1 ; }
29372934;
29382935
2939- GenericType :ident {$$ =$1 ; }
2936+ Generic :generic
2937+ {
2938+ $$ =$1 ;
2939+ }
2940+ ;
2941+
2942+ generic :ident {$$ =$1 ; }
2943+ | TYPE_P {$$ = make_str(" type" ); }
29402944| ECPGKeywords {$$ =$1 ; }
29412945| ECPGTypeName {$$ =$1 ; }
29422946;
@@ -3170,21 +3174,21 @@ opt_interval: datetime{ $$ = $1; }
31703174 * Define row_descriptor to allow yacc to break the reduce/reduce conflict
31713175 * with singleton expressions.
31723176*/
3173- row_expr :' (' row_descriptor ' )' IN ' ( ' SelectStmt ' ) '
3177+ row_expr :' (' row_descriptor ' )' IN select_with_parens
31743178{
3175- $$ = cat_str(5 , make_str(" (" ),$2 , make_str(" ) in( " ),$6 , make_str( " ) " ) );
3179+ $$ = cat_str(4 , make_str(" (" ),$2 , make_str(" ) in" ),$5 );
31763180}
3177- | ' (' row_descriptor ' )' NOT IN ' ( ' SelectStmt ' ) '
3181+ | ' (' row_descriptor ' )' NOT IN select_with_parens
31783182{
3179- $$ = cat_str(5 , make_str(" (" ),$2 , make_str(" ) not in( " ),$7 , make_str( " ) " ) );
3183+ $$ = cat_str(4 , make_str(" (" ),$2 , make_str(" ) not in" ),$6 );
31803184}
3181- | ' (' row_descriptor ' )' all_Op sub_type ' ( ' SelectStmt ' ) '
3185+ | ' (' row_descriptor ' )' all_Op sub_type select_with_parens
31823186{
3183- $$ = cat_str(8 , make_str(" (" ),$2 , make_str(" )" ),$4 ,$5 ,make_str( " ( " ), $7 , make_str( " ) " ) );
3187+ $$ = cat_str(6 , make_str(" (" ),$2 , make_str(" )" ),$4 ,$5 ,$6 );
31843188}
3185- | ' (' row_descriptor ' )' all_Op ' ( ' SelectStmt ' ) '
3189+ | ' (' row_descriptor ' )' all_Op select_with_parens
31863190{
3187- $$ = cat_str(7 , make_str(" (" ),$2 , make_str(" )" ),$4 ,make_str( " ( " ), $6 , make_str( " ) " ) );
3191+ $$ = cat_str(5 , make_str(" (" ),$2 , make_str(" )" ),$4 ,$5 );
31883192}
31893193| ' (' row_descriptor ' )' all_Op ' (' row_descriptor ' )'
31903194{
@@ -3349,17 +3353,17 @@ a_expr: c_expr
33493353{
33503354$$ = cat_str(5 ,$1 , make_str(" not between" ),$4 , make_str(" and" ),$6 );
33513355}
3352- | a_expr IN ' ( ' in_expr ' ) '
3356+ | a_expr IN in_expr
33533357{
3354- $$ = cat_str(4 ,$1 , make_str(" in ( " ),$4 , make_str( " ) " ) );
3358+ $$ = cat_str(3 ,$1 , make_str(" in" ),$3 );
33553359}
3356- | a_expr NOT IN ' ( ' in_expr ' ) '
3360+ | a_expr NOT IN in_expr
33573361{
3358- $$ = cat_str(4 ,$1 , make_str(" not in( " ),$5 , make_str( " ) " ) );
3362+ $$ = cat_str(3 ,$1 , make_str(" not in" ),$4 );
33593363}
3360- | a_expr all_Op sub_type ' ( ' SelectStmt ' ) '
3364+ | a_expr all_Op sub_type select_with_parens
33613365{
3362- $$ = cat_str(6 ,$1 ,$2 ,$3 ,make_str( " ( " ), $5 , make_str( " ) " ) );
3366+ $$ = cat_str(4 ,$1 ,$2 ,$3 ,$4 );
33633367}
33643368| row_expr
33653369{$$ =$1 ; }
@@ -3494,10 +3498,10 @@ c_expr: attr
34943498{$$ = cat_str(3 , make_str(" trim(trailing" ),$4 , make_str(" )" )); }
34953499| TRIM ' (' trim_list ' )'
34963500{$$ = cat_str(3 , make_str(" trim(" ),$3 , make_str(" )" )); }
3497- | ' ( ' select_no_parens ' ) '
3498- {$$ =cat_str( 3 , make_str( " ( " ), $2 , make_str( " ) " )) ; }
3499- | EXISTS ' ( ' SelectStmt ' ) '
3500- {$$ =cat_str( 3 , make_str(" exists( " ),$3 , make_str( " ) " ) ); }
3501+ | select_with_parens % prec UMINUS
3502+ {$$ =$1 ; }
3503+ | EXISTS select_with_parens
3504+ {$$ =cat2_str( make_str(" exists" ),$2 ); }
35013505;
35023506/*
35033507 * This used to use ecpg_expr, but since there is no shift/reduce conflict
@@ -3583,12 +3587,12 @@ trim_list: a_expr FROM expr_list
35833587{$$ =$1 ; }
35843588;
35853589
3586- in_expr :SelectStmt
3590+ in_expr :select_with_parens
35873591{
35883592$$ =$1 ;
35893593}
3590- | in_expr_nodes
3591- {$$ =$1 ; }
3594+ | ' ( ' in_expr_nodes ' ) '
3595+ {$$ =cat_str( 3 , make_str( " ( " ), $2 , make_str( " ) " )) ; }
35923596;
35933597
35943598in_expr_nodes :a_expr
@@ -5069,7 +5073,6 @@ TokenId: ABSOLUTE{ $$ = make_str("absolute"); }
50695073| TRIGGER {$$ = make_str(" trigger" ); }
50705074| TRUNCATE {$$ = make_str(" truncate" ); }
50715075| TRUSTED {$$ = make_str(" trusted" ); }
5072- | TYPE_P {$$ = make_str(" type" ); }
50735076| UNLISTEN {$$ = make_str(" unlisten" ); }
50745077| UNTIL {$$ = make_str(" until" ); }
50755078| UPDATE {$$ = make_str(" update" ); }
@@ -5103,7 +5106,6 @@ ECPGColLabel: ECPGColId{ $$ = $1; }
51035106| ALL {$$ = make_str(" all" ); }
51045107| ANALYSE {$$ = make_str(" analyse" ); }
51055108| ANALYZE {$$ = make_str(" analyze" ); }
5106- | AND {$$ = make_str(" and" ); }
51075109| ANY {$$ = make_str(" any" ); }
51085110| ASC {$$ = make_str(" asc" ); }
51095111| BETWEEN {$$ = make_str(" between" ); }
@@ -5198,7 +5200,6 @@ ECPGColLabel: ECPGColId{ $$ = $1; }
51985200| TABLE {$$ = make_str(" table" ); }
51995201| THEN {$$ = make_str(" then" ); }
52005202| TO {$$ = make_str(" to" ); }
5201- | TRAILING {$$ = make_str(" trailing" ); }
52025203| TRANSACTION {$$ = make_str(" transaction" ); }
52035204| TRIM {$$ = make_str(" trim" ); }
52045205| TRUE_P {$$ = make_str(" true" ); }