1010 *
1111 *
1212 * IDENTIFICATION
13- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.93 1998/01/17 05:01:34 momjian Exp $
13+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.94 1998/01/19 05:06:15 momjian Exp $
1414 *
1515 * HISTORY
1616 * AUTHORDATEMAJOR EVENT
4848
4949static char saved_relname[NAMEDATALEN]; /* need this for complex attributes */
5050static bool QueryIsRule = FALSE;
51- staticNode *saved_In_Expr;
51+ staticList *saved_In_Expr = NIL ;
5252static Oid*param_type_info;
5353static intpfunc_num_args;
5454extern List *parsetree;
@@ -242,7 +242,7 @@ Oidparam_type(int t); /* used in parse_expr.c */
242242 */
243243
244244/* Keywords (in SQL92 reserved words) */
245- %tokenACTION, ADD, ALL, ALTER, AND, AS, ASC,
245+ %tokenACTION, ADD, ALL, ALTER, AND,ANY AS, ASC,
246246BEGIN_TRANS, BETWEEN, BOTH, BY,
247247CASCADE, CAST, CHAR, CHARACTER, CHECK, CLOSE, COLLATE, COLUMN, COMMIT,
248248CONSTRAINT, CREATE, CROSS, CURRENT, CURRENT_DATE, CURRENT_TIME,
@@ -2871,24 +2871,52 @@ row_expr: '(' row_descriptor ')' IN '(' SubSelect ')'
28712871{
28722872SubLink *n = makeNode(SubLink);
28732873n->lefthand = $2;
2874- n->subLinkType = IN_SUBLINK;
2874+ n->oper = lcons("=",NIL);
2875+ n->useor = false;
2876+ n->subLinkType = ANY_SUBLINK;
28752877n->subselect = $6;
28762878$$ = (Node *)n;
28772879}
28782880| '(' row_descriptor ')' NOT IN '(' SubSelect ')'
28792881{
28802882SubLink *n = makeNode(SubLink);
28812883n->lefthand = $2;
2882- n->subLinkType = NOTIN_SUBLINK;
2884+ n->oper = lcons("<>",NIL);
2885+ n->useor = true;
2886+ n->subLinkType = ALL_SUBLINK;
2887+ n->subselect = $7;
2888+ $$ = (Node *)n;
2889+ }
2890+ | '(' row_descriptor ')' Op ANY '(' SubSelect ')'
2891+ {
2892+ SubLink *n = makeNode(SubLink);
2893+ n->lefthand = $2;
2894+ n->oper = lcons($4,NIL);
2895+ n->useor = false;
2896+ n->subLinkType = ANY_SUBLINK;
2897+ n->subselect = $7;
2898+ $$ = (Node *)n;
2899+ }
2900+ | '(' row_descriptor ')' Op ALL '(' SubSelect ')'
2901+ {
2902+ SubLink *n = makeNode(SubLink);
2903+ n->lefthand = $2;
2904+ n->oper = lcons($4,NIL);
2905+ n->useor = false;
2906+ n->subLinkType = ALL_SUBLINK;
28832907n->subselect = $7;
28842908$$ = (Node *)n;
28852909}
28862910| '(' row_descriptor ')' Op '(' SubSelect ')'
28872911{
28882912SubLink *n = makeNode(SubLink);
28892913n->lefthand = $2;
2890- n->subLinkType = OPER_SUBLINK;
28912914n->oper = lcons($4, NIL);
2915+ if (strcmp($4,"<>") == 0)
2916+ n->useor = true;
2917+ else
2918+ n->useor = false;
2919+ n->subLinkType = EXPR_SUBLINK;
28922920n->subselect = $6;
28932921$$ = (Node *)n;
28942922}
@@ -3114,17 +3142,13 @@ a_expr: attr opt_indirection
31143142n->args = NIL;
31153143$$ = (Node *)n;
31163144}
3117- /* We probably need to define an "exists" node,
3118- *since the optimizer could choose to find only one match.
3119- * Perhaps the first implementation could just check for
3120- *count(*) > 0? - thomas 1997-07-19
3121- */
31223145| EXISTS '(' SubSelect ')'
31233146{
31243147SubLink *n = makeNode(SubLink);
31253148n->lefthand = NIL;
3126- n->subLinkType =EXISTS_SUBLINK ;
3149+ n->useor =false ;
31273150n->oper = NIL;
3151+ n->subLinkType = EXISTS_SUBLINK;
31283152n->subselect = $3;
31293153$$ = (Node *)n;
31303154}
@@ -3239,26 +3263,52 @@ a_expr: attr opt_indirection
32393263makeA_Expr(OP, "<", $1, $4),
32403264makeA_Expr(OP, ">", $1, $6));
32413265}
3242- | a_expr IN { saved_In_Expr =$1 ; } '(' in_expr ')'
3266+ | a_expr IN { saved_In_Expr =lcons($1,saved_In_Expr) ; } '(' in_expr ')' { saved_In_Expr = lnext(saved_In_Expr); }
32433267{
32443268if (nodeTag($5) == T_SubLink)
32453269{
3246- ((SubLink *)$5)->lefthand = lcons($1, NIL);
3247- ((SubLink *)$5)->subLinkType = IN_SUBLINK;
3248- $$ = (Node *)$5;
3270+ SubLink *n = (SubLink *)$5;
3271+ n->lefthand = lcons($1, NIL);
3272+ n->oper = lcons("=",NIL);
3273+ n->useor = false;
3274+ n->subLinkType = ANY_SUBLINK;
3275+ $$ = (Node *)n;
32493276}
32503277else$$ = $5;
32513278}
3252- | a_expr NOT IN { saved_In_Expr =$1 ; } '(' not_in_expr ')'
3279+ | a_expr NOT IN { saved_In_Expr =lcons($1,saved_In_Expr) ; } '(' not_in_expr ')' { saved_In_Expr = lnext(saved_In_Expr); }
32533280{
32543281if (nodeTag($6) == T_SubLink)
32553282{
3256- ((SubLink *)$6)->lefthand = lcons($1, NIL);
3257- ((SubLink *)$6)->subLinkType = NOTIN_SUBLINK;
3258- $$ = (Node *)$6;
3283+ SubLink *n = (SubLink *)$6;
3284+ n->lefthand = lcons($1, NIL);
3285+ n->oper = lcons("<>",NIL);
3286+ n->useor = false;
3287+ n->subLinkType = ALL_SUBLINK;
3288+ $$ = (Node *)n;
32593289}
32603290else$$ = $6;
32613291}
3292+ | a_expr Op ANY '(' SubSelect ')'
3293+ {
3294+ SubLink *n = makeNode(SubLink);
3295+ n->lefthand = lcons($1,NIL);
3296+ n->oper = lcons($2,NIL);
3297+ n->useor = false;
3298+ n->subLinkType = ANY_SUBLINK;
3299+ n->subselect = $5;
3300+ $$ = (Node *)n;
3301+ }
3302+ | a_expr Op ALL '(' SubSelect ')'
3303+ {
3304+ SubLink *n = makeNode(SubLink);
3305+ n->lefthand = lcons($1, NULL);
3306+ n->oper = lcons($2,NIL);
3307+ n->useor = false;
3308+ n->subLinkType = ALL_SUBLINK;
3309+ n->subselect = $5;
3310+ $$ = (Node *)n;
3311+ }
32623312| a_expr AND a_expr
32633313{$$ = makeA_Expr(AND, NULL, $1, $3); }
32643314| a_expr OR a_expr
@@ -3480,10 +3530,10 @@ in_expr: SubSelect
34803530;
34813531
34823532in_expr_nodes: AexprConst
3483- {$$ = makeA_Expr(OP, "=", saved_In_Expr, $1); }
3533+ {$$ = makeA_Expr(OP, "=",lfirst( saved_In_Expr) , $1); }
34843534| in_expr_nodes ',' AexprConst
34853535{$$ = makeA_Expr(OR, NULL, $1,
3486- makeA_Expr(OP, "=", saved_In_Expr, $3));
3536+ makeA_Expr(OP, "=",lfirst( saved_In_Expr) , $3));
34873537}
34883538;
34893539
@@ -3498,10 +3548,10 @@ not_in_expr: SubSelect
34983548;
34993549
35003550not_in_expr_nodes: AexprConst
3501- {$$ = makeA_Expr(OP, "<>", saved_In_Expr, $1); }
3551+ {$$ = makeA_Expr(OP, "<>",lfirst( saved_In_Expr) , $1); }
35023552| not_in_expr_nodes ',' AexprConst
35033553{$$ = makeA_Expr(AND, NULL, $1,
3504- makeA_Expr(OP, "<>", saved_In_Expr, $3));
3554+ makeA_Expr(OP, "<>",lfirst( saved_In_Expr) , $3));
35053555}
35063556;
35073557