@@ -24,8 +24,7 @@ charerrortext[128];
24
24
char *connection =NULL ;
25
25
char *input_filename =NULL ;
26
26
27
- static int QueryIsRule =0 , ForUpdateNotAllowed =0 , FoundInto =0 ;
28
- static int FoundSort =0 ;
27
+ static int QueryIsRule =0 , FoundInto =0 ;
29
28
static int initializer =0 ;
30
29
static struct this_type actual_type[STRUCT_DEPTH];
31
30
static char *actual_storage[STRUCT_DEPTH];
@@ -300,7 +299,7 @@ make_name(void)
300
299
%type <str> opt_decimal Character character opt_varying opt_charset
301
300
%type <str> opt_collate datetime opt_timezone opt_interval table_ref
302
301
%type <str> row_expr row_descriptor row_list ConstDatetime opt_chain
303
- %type <str> SelectStmt SubSelect result OptTemp ConstraintAttributeSpec
302
+ %type <str> SelectStmt select_subclause result OptTemp ConstraintAttributeSpec
304
303
%type <str> opt_table opt_all sort_clause sortby_list ConstraintAttr
305
304
%type <str> sortby OptUseOp opt_inh_star relation_name_list name_list
306
305
%type <str> group_clause having_clause from_clause opt_distinct
@@ -1972,33 +1971,15 @@ func_args_list: func_arg{ $$ = $1; }
1972
1971
{$$ = cat_str(3 ,$1 , make_str(" ," ),$3 ); }
1973
1972
;
1974
1973
1975
- /* Would be nice to use the full Typename production for these fields,
1976
- * but that one sometimes dives into the catalogs looking for valid types.
1977
- * Arguments like "opaque" are valid when defining functions,
1978
- * so that won't work here. The only thing we give up is array notation,
1979
- * which isn't meaningful in this context anyway.
1980
- * - thomas 2000-03-25
1981
- * The following productions are difficult, since it is difficult to
1982
- * distinguish between TokenId and SimpleTypename:
1983
- opt_arg TokenId SimpleTypename
1984
- {
1985
- $$ = $3;
1986
- }
1987
- | TokenId SimpleTypename
1988
- {
1989
- $$ = $2;
1990
- }
1991
- */
1992
-
1993
- func_arg :opt_arg SimpleTypename
1974
+ func_arg :opt_arg Typename
1994
1975
{
1995
1976
/* We can catch over-specified arguments here if we want to,
1996
1977
* but for now better to silently swallow typmod, etc.
1997
1978
* - thomas 2000-03-22
1998
1979
*/
1999
1980
$$ = cat2_str($1 ,$2 );
2000
1981
}
2001
- | SimpleTypename
1982
+ | Typename
2002
1983
{
2003
1984
$$ =$1 ;
2004
1985
}
@@ -2020,19 +2001,14 @@ opt_arg: IN { $$ = make_str("in"); }
2020
2001
func_as :Sconst {$$ =$1 ; }
2021
2002
| Sconst ' ,' Sconst {$$ = cat_str(3 ,$1 , make_str(" ," ),$3 ); }
2022
2003
2023
- func_return :SimpleTypename
2004
+ func_return :Typename
2024
2005
{
2025
2006
/* We can catch over-specified arguments here if we want to,
2026
2007
* but for now better to silently swallow typmod, etc.
2027
2008
* - thomas 2000-03-22
2028
2009
*/
2029
2010
$$ =$1 ;
2030
2011
}
2031
- | SETOF SimpleTypename
2032
- {
2033
-
2034
- $$ = cat2_str(make_str(" setof" ),$2 );
2035
- }
2036
2012
;
2037
2013
2038
2014
/* ****************************************************************************
@@ -2071,7 +2047,7 @@ RemoveAggrStmt: DROP AGGREGATE name aggr_argtype
2071
2047
}
2072
2048
;
2073
2049
2074
- aggr_argtype :name {$$ =$1 ; }
2050
+ aggr_argtype :Typename {$$ =$1 ; }
2075
2051
| ' *' {$$ = make_str(" *" ); }
2076
2052
;
2077
2053
@@ -2089,15 +2065,15 @@ RemoveOperStmt: DROP OPERATOR all_Op '(' oper_argtypes ')'
2089
2065
}
2090
2066
;
2091
2067
2092
- oper_argtypes :name
2068
+ oper_argtypes :Typename
2093
2069
{
2094
2070
mmerror (ET_ERROR," parser: argument type missing (use NONE for unary operators)" );
2095
2071
}
2096
- | name ' ,' name
2072
+ | Typename ' ,' Typename
2097
2073
{$$ = cat_str(3 ,$1 , make_str(" ," ),$3 ); }
2098
- | NONE ' ,' name /* left unary*/
2074
+ | NONE ' ,' Typename /* left unary*/
2099
2075
{$$ = cat2_str(make_str(" none," ),$3 ); }
2100
- | name ' ,' NONE /* right unary*/
2076
+ | Typename ' ,' NONE /* right unary*/
2101
2077
{$$ = cat2_str($1 , make_str(" , none" )); }
2102
2078
;
2103
2079
@@ -2471,14 +2447,8 @@ insert_rest: VALUES '(' target_list ')'
2471
2447
{
2472
2448
$$ = make_str(" default values" );
2473
2449
}
2474
- /* We want the full power of SelectStatements including INTERSECT and EXCEPT
2475
- * for insertion. However, we can't support sort or limit clauses.
2476
- */
2477
2450
| SelectStmt
2478
2451
{
2479
- if (FoundSort !=0 )
2480
- mmerror (ET_ERROR," ORDER BY is not allowed in INSERT/SELECT" );
2481
-
2482
2452
$$ =$1 ;
2483
2453
}
2484
2454
| ' (' columnList ' )' VALUES ' (' target_list ' )'
@@ -2487,9 +2457,6 @@ insert_rest: VALUES '(' target_list ')'
2487
2457
}
2488
2458
| ' (' columnList ' )' SelectStmt
2489
2459
{
2490
- if (FoundSort !=0 )
2491
- mmerror (ET_ERROR," ORDER BY is not all owed in INSERT/SELECT" );
2492
-
2493
2460
$$ = cat_str(4 , make_str(" (" ),$2 , make_str(" )" ),$4 );
2494
2461
}
2495
2462
;
@@ -2568,9 +2535,7 @@ UpdateStmt: UPDATE opt_only relation_name
2568
2535
*CURSOR STATEMENTS
2569
2536
*
2570
2537
*****************************************************************************/
2571
- CursorStmt :DECLARE name opt_cursor CURSOR FOR
2572
- { ForUpdateNotAllowed =1 ; }
2573
- SelectStmt
2538
+ CursorStmt :DECLARE name opt_cursor CURSOR FOR SelectStmt
2574
2539
{
2575
2540
struct cursor *ptr, *this ;
2576
2541
@@ -2590,7 +2555,7 @@ CursorStmt: DECLARE name opt_cursor CURSOR FOR
2590
2555
this ->next = cur;
2591
2556
this ->name =$2 ;
2592
2557
this ->connection = connection;
2593
- this ->command = cat_str(5 , make_str(" declare" ), mm_strdup($2 ),$3 , make_str(" cursor for" ),$7 );
2558
+ this ->command = cat_str(5 , make_str(" declare" ), mm_strdup($2 ),$3 , make_str(" cursor for" ),$6 );
2594
2559
this ->argsinsert = argsinsert;
2595
2560
this ->argsresult = argsresult;
2596
2561
argsinsert = argsresult =NULL ;
@@ -2615,70 +2580,55 @@ opt_cursor: BINARY { $$ = make_str("binary"); }
2615
2580
*
2616
2581
*****************************************************************************/
2617
2582
2618
- /* The new 'SelectStmt' rule adapted for the optional use of INTERSECT EXCEPT a nd UNION
2619
- * accepts the use of '(' and ')' to select an order of set operations.
2620
- * The rule returns a SelectStmt Node having the set operations attached to
2621
- * unionClause and intersectClause (NIL if no set operations were present)
2622
- */
2623
-
2624
- SelectStmt :select_clause
2625
- { FoundSort =0 ; }
2626
- sort_clause for_update_clause opt_select_limit
2583
+ SelectStmt :select_clause sort_clause for_update_clause opt_select_limit
2627
2584
{
2628
- if (strlen($4 ) >0 && ForUpdateNotAllowed !=0 )
2629
- mmerror (ET_ERROR," FOR UPDATE is not allowed in this context" );
2630
-
2631
- ForUpdateNotAllowed =0 ;
2632
- $$ = cat_str(4 ,$1 ,$3 ,$4 ,$5 );
2585
+ $$ = cat_str(4 ,$1 ,$2 ,$3 ,$4 );
2633
2586
}
2634
2587
2635
2588
/* This rule parses Select statements including UNION INTERSECT and EXCEPT.
2636
2589
* '(' and ')' can be used to specify the order of the operations
2637
2590
* (UNION EXCEPT INTERSECT). Without the use of '(' and ')' we want the
2638
2591
* operations to be ordered per the precedence specs at the head of this file.
2639
2592
*
2640
- * The sort_clause is not handled here!
2593
+ * Since parentheses around SELECTs also appear in the expression grammar,
2594
+ * there is a parse ambiguity if parentheses are allowed at the top level of a
2595
+ * select_clause: are the parens part of the expression or part of the select?
2596
+ * We separate select_clause into two levels to resolve this: select_clause
2597
+ * can have top-level parentheses, select_subclause cannot.
2598
+ * Note that sort clauses cannot be included at this level --- a sort clau
2599
+ * can only appear at the end of the complete Select, and it will be handl
2600
+ * by the topmost SelectStmt rule. Likewise FOR UPDATE and LIMIT.
2641
2601
*/
2642
- select_clause :' (' select_clause ' )'
2602
+
2603
+ select_clause :' (' select_subclause ' )'
2643
2604
{
2644
2605
$$ = cat_str(3 , make_str(" (" ),$2 , make_str(" )" ));
2645
2606
}
2646
- | SubSelect
2607
+ | select_subclause
2647
2608
{
2648
- FoundInto =0 ;
2609
+ FoundInto =0 ;
2649
2610
$$ =$1 ;
2650
2611
}
2651
- | select_clause EXCEPT opt_all select_clause
2652
- {
2653
- if (strlen($3 ) !=0 )
2654
- mmerror (ET_WARN," EXCEPT ALL is not implemented yet." );
2655
-
2656
- $$ = cat_str(4 ,$1 , make_str(" except" ),$3 ,$4 );
2657
- ForUpdateNotAllowed =1 ;
2658
- }
2659
- | select_clause UNION opt_all select_clause
2660
- {
2661
- $$ = cat_str(4 ,$1 , make_str(" union" ),$3 ,$4 );
2662
- ForUpdateNotAllowed =1 ;
2663
- }
2664
- | select_clause INTERSECT opt_all select_clause
2665
- {
2666
- if (strlen($3 ) !=0 )
2667
- mmerror (ET_WARN," INTERSECT ALL is not implemented yet." );
2668
-
2669
- $$ = cat_str(4 ,$1 , make_str(" intersect" ),$3 ,$4 );
2670
- ForUpdateNotAllowed =1 ;
2671
- }
2672
2612
;
2673
2613
2674
- SubSelect :SELECT opt_distinct target_list
2614
+ select_subclause :SELECT opt_distinct target_list
2675
2615
result from_clause where_clause
2676
2616
group_clause having_clause
2677
2617
{
2678
- if (strlen($7 ) >0 || strlen($8 ) >0 )
2679
- ForUpdateNotAllowed =1 ;
2680
2618
$$ = cat_str(8 , make_str(" select" ),$2 ,$3 ,$4 ,$5 ,$6 ,$7 ,$8 );
2681
2619
}
2620
+ | select_clause UNION opt_all select_clause
2621
+ {
2622
+ $$ = cat_str(4 ,$1 , make_str(" union" ),$3 ,$4 );
2623
+ }
2624
+ | select_clause INTERSECT opt_all select_clause
2625
+ {
2626
+ $$ = cat_str(4 ,$1 , make_str(" intersect" ),$3 ,$4 );
2627
+ }
2628
+ | select_clause EXCEPT opt_all select_clause
2629
+ {
2630
+ $$ = cat_str(4 ,$1 , make_str(" except" ),$3 ,$4 );
2631
+ }
2682
2632
;
2683
2633
2684
2634
result :INTO OptTempTableName {
@@ -2747,7 +2697,6 @@ opt_distinct: DISTINCT{ $$ = make_str("distinct"); }
2747
2697
;
2748
2698
2749
2699
sort_clause :ORDER BY sortby_list {
2750
- FoundSort =1 ;
2751
2700
$$ = cat2_str(make_str(" order by" ),$3 );
2752
2701
}
2753
2702
| /* EMPTY*/ {$$ = EMPTY; }
@@ -2880,7 +2829,7 @@ table_ref: relation_expr
2880
2829
{
2881
2830
cat2_str ($1 , $2 );
2882
2831
}
2883
- | ' (' select_clause ' )' alias_clause
2832
+ | ' (' select_subclause ' )' alias_clause
2884
2833
{
2885
2834
cat_str (4 , make_str(" (" ), $2, make_str(" )" ), $4);
2886
2835
}
@@ -3299,19 +3248,19 @@ opt_interval: datetime{ $$ = $1; }
3299
3248
* Define row_descriptor to allow yacc to break the reduce/reduce conflict
3300
3249
* with singleton expressions.
3301
3250
*/
3302
- row_expr :' (' row_descriptor ' )' IN ' (' SubSelect ' )'
3251
+ row_expr :' (' row_descriptor ' )' IN ' (' select_subclause ' )'
3303
3252
{
3304
3253
$$ = cat_str(5 , make_str(" (" ),$2 , make_str(" ) in (" ),$6 , make_str(" )" ));
3305
3254
}
3306
- | ' (' row_descriptor ' )' NOT IN ' (' SubSelect ' )'
3255
+ | ' (' row_descriptor ' )' NOT IN ' (' select_subclause ' )'
3307
3256
{
3308
3257
$$ = cat_str(5 , make_str(" (" ),$2 , make_str(" ) not in (" ),$7 , make_str(" )" ));
3309
3258
}
3310
- | ' (' row_descriptor ' )' all_Op sub_type ' (' SubSelect ' )'
3259
+ | ' (' row_descriptor ' )' all_Op sub_type ' (' select_subclause ' )'
3311
3260
{
3312
3261
$$ = cat_str(8 , make_str(" (" ),$2 , make_str(" )" ),$4 ,$5 , make_str(" (" ),$7 , make_str(" )" ));
3313
3262
}
3314
- | ' (' row_descriptor ' )' all_Op ' (' SubSelect ' )'
3263
+ | ' (' row_descriptor ' )' all_Op ' (' select_subclause ' )'
3315
3264
{
3316
3265
$$ = cat_str(7 , make_str(" (" ),$2 , make_str(" )" ),$4 , make_str(" (" ),$6 , make_str(" )" ));
3317
3266
}
@@ -3491,7 +3440,7 @@ a_expr: c_expr
3491
3440
{
3492
3441
$$ = cat_str(4 ,$1 , make_str(" not in (" ),$5 , make_str(" )" ));
3493
3442
}
3494
- | a_expr all_Op sub_type ' (' SubSelect ' )'
3443
+ | a_expr all_Op sub_type ' (' select_subclause ' )'
3495
3444
{
3496
3445
$$ = cat_str(6 ,$1 ,$2 ,$3 , make_str(" (" ),$5 , make_str(" )" ));
3497
3446
}
@@ -3638,9 +3587,9 @@ c_expr: attr
3638
3587
{$$ = cat_str(3 , make_str(" trim(trailing" ),$4 , make_str(" )" )); }
3639
3588
| TRIM ' (' trim_list ' )'
3640
3589
{$$ = cat_str(3 , make_str(" trim(" ),$3 , make_str(" )" )); }
3641
- | ' (' SubSelect ' )'
3590
+ | ' (' select_subclause ' )'
3642
3591
{$$ = cat_str(3 , make_str(" (" ),$2 , make_str(" )" )); }
3643
- | EXISTS ' (' SubSelect ' )'
3592
+ | EXISTS ' (' select_subclause ' )'
3644
3593
{$$ = cat_str(3 , make_str(" exists(" ),$3 , make_str(" )" )); }
3645
3594
;
3646
3595
/*
@@ -3719,7 +3668,7 @@ trim_list: a_expr FROM expr_list
3719
3668
{$$ =$1 ; }
3720
3669
;
3721
3670
3722
- in_expr :SubSelect
3671
+ in_expr :select_subclause
3723
3672
{
3724
3673
$$ =$1 ;
3725
3674
}
@@ -5164,6 +5113,7 @@ ECPGColId: ident{ $$ = $1; }
5164
5113
| TokenId {$$ =$1 ; }
5165
5114
| INTERVAL {$$ = make_str(" interval" ); }
5166
5115
| NATIONAL {$$ = make_str(" national" ); }
5116
+ | NONE {$$ = make_str(" none" ); }
5167
5117
| PATH_P {$$ = make_str(" path_p" ); }
5168
5118
| SERIAL {$$ = make_str(" serial" ); }
5169
5119
| TIME {$$ = make_str(" time" ); }
@@ -5177,7 +5127,7 @@ ECPGColLabel: ECPGColId{ $$ = $1; }
5177
5127
| ANALYZE {$$ = make_str(" analyze" ); }
5178
5128
| ANY {$$ = make_str(" any" ); }
5179
5129
| ASC {$$ = make_str(" asc" ); }
5180
- | BETWEEN {$$ = make_str(" between" ); }
5130
+ | BETWEEN {$$ = make_str(" between" ); }
5181
5131
| BINARY {$$ = make_str(" binary" ); }
5182
5132
| BIT {$$ = make_str(" bit" ); }
5183
5133
| BOTH {$$ = make_str(" both" ); }
@@ -5236,7 +5186,6 @@ ECPGColLabel: ECPGColId{ $$ = $1; }
5236
5186
| NATURAL {$$ = make_str(" natural" ); }
5237
5187
| NCHAR {$$ = make_str(" nchar" ); }
5238
5188
| NEW {$$ = make_str(" new" ); }
5239
- | NONE {$$ = make_str(" none" ); }
5240
5189
| NOT {$$ = make_str(" not" ); }
5241
5190
| NOTNULL {$$ = make_str(" notnull" ); }
5242
5191
| NULLIF {$$ = make_str(" nullif" ); }