Skip junk nodes when comparing UNION target list lengths.
authorBruce Momjian
Mon, 17 May 1999 18:22:19 +0000 (18:22 +0000)
committerBruce Momjian
Mon, 17 May 1999 18:22:19 +0000 (18:22 +0000)
src/backend/parser/parse_clause.c
src/backend/rewrite/rewriteHandler.c

index 507ebc2e719b744e30fc2cdac15e198eb2de2169..a3eafab36cbee8697d9f172d6d212fbacca2d889 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.33 1999/05/17 17:03:32 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.34 1999/05/17 18:22:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -767,8 +767,17 @@ transformUnionClause(List *unionClause, List *targetlist)
            Query      *query = (Query *) lfirst(qlist_item);
            List       *prev_target = targetlist;
            List       *next_target;
+           int         prev_len = 0, next_len = 0;
 
-           if (length(targetlist) != length(query->targetList))
+           foreach(prev_target, targetlist)
+               if (!((TargetEntry *) lfirst(prev_target))->resdom->resjunk)
+                   prev_len++;
+
+           foreach(next_target, query->targetList)
+               if (!((TargetEntry *) lfirst(next_target))->resdom->resjunk)
+                   next_len++;
+                       
+           if (prev_len != next_len)
                elog(ERROR, "Each UNION clause must have the same number of columns");
 
            foreach(next_target, query->targetList)
index b2b8c051f60813da06f4819feff038511577c78d..26626d0bb8a52dfc2f6aa7b572aecc263f632998 100644 (file)
@@ -6,7 +6,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.42 1999/05/17 17:03:38 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.43 1999/05/17 18:22:19 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2762,11 +2762,20 @@ QueryRewrite(Query *parsetree)
  * attributes and the types are compatible */
 void check_targetlists_are_compatible(List *prev_target, List *current_target)
 {
-  List *next_target;
+  List  *tl, *next_target;
+  int  prev_len = 0, next_len = 0;
+
+  foreach(tl, prev_target)
+   if (!((TargetEntry *) lfirst(tl))->resdom->resjunk)
+       prev_len++;
+
+  foreach(next_target, current_target)
+   if (!((TargetEntry *) lfirst(next_target))->resdom->resjunk)
+       next_len++;
   
-  if (length(prev_target) != 
-      length(current_target))
-    elog(ERROR,"Each UNION | EXCEPT | INTERSECT query must have the same number of columns.");           
+  if (prev_len != next_len)
+    elog(ERROR,"Each UNION | EXCEPT | INTERSECT query must have the same number of columns.");
+
   foreach(next_target, current_target)
     {
       Oid          itype;