Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 19c4e86

Browse files
committed
Skip junk nodes when comparing UNION target list lengths.
1 parent 585c967 commit 19c4e86

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/backend/parser/parse_clause.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.33 1999/05/17 17:03:32 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.34 1999/05/17 18:22:18 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -767,8 +767,17 @@ transformUnionClause(List *unionClause, List *targetlist)
767767
Query *query = (Query *) lfirst(qlist_item);
768768
List *prev_target = targetlist;
769769
List *next_target;
770+
int prev_len = 0, next_len = 0;
770771

771-
if (length(targetlist) != length(query->targetList))
772+
foreach(prev_target, targetlist)
773+
if (!((TargetEntry *) lfirst(prev_target))->resdom->resjunk)
774+
prev_len++;
775+
776+
foreach(next_target, query->targetList)
777+
if (!((TargetEntry *) lfirst(next_target))->resdom->resjunk)
778+
next_len++;
779+
780+
if (prev_len != next_len)
772781
elog(ERROR, "Each UNION clause must have the same number of columns");
773782

774783
foreach(next_target, query->targetList)

src/backend/rewrite/rewriteHandler.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.42 1999/05/17 17:03:38 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.43 1999/05/17 18:22:19 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -2762,11 +2762,20 @@ QueryRewrite(Query *parsetree)
27622762
* attributes and the types are compatible */
27632763
void check_targetlists_are_compatible(List *prev_target, List *current_target)
27642764
{
2765-
List *next_target;
2765+
List *tl, *next_target;
2766+
int prev_len = 0, next_len = 0;
2767+
2768+
foreach(tl, prev_target)
2769+
if (!((TargetEntry *) lfirst(tl))->resdom->resjunk)
2770+
prev_len++;
2771+
2772+
foreach(next_target, current_target)
2773+
if (!((TargetEntry *) lfirst(next_target))->resdom->resjunk)
2774+
next_len++;
27662775

2767-
if (length(prev_target) !=
2768-
length(current_target))
2769-
elog(ERROR,"Each UNION | EXCEPT | INTERSECT query must have the same number of columns.");
2776+
if (prev_len != next_len)
2777+
elog(ERROR,"Each UNION | EXCEPT | INTERSECT query must have the same number of columns.");
2778+
27702779
foreach(next_target, current_target)
27712780
{
27722781
Oid itype;

0 commit comments

Comments
 (0)