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)
* 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;