Skip to content

Commit 9fdbbdc

Browse files
author
Thomas G. Lockhart
committed
Fix for UNION selects with constant NULL expressions; e.g.
SELECT 1 UNION SELECT NULL;
1 parent 3733bd4 commit 9fdbbdc

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/backend/parser/parse_clause.c

Lines changed: 21 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.20 1998/07/09 14:34:05 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.21 1998/07/14 03:51:42 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -472,7 +472,25 @@ transformUnionClause(List *unionClause, List *targetlist)
472472
Oid otype;
473473
otype = ((TargetEntry *)lfirst(prev_target))->resdom->restype;
474474
itype = ((TargetEntry *)lfirst(next_target))->resdom->restype;
475-
if (itype != otype)
475+
476+
#ifdef PARSEDEBUG
477+
printf("transformUnionClause: types are %d -> %d\n", itype, otype);
478+
#endif
479+
480+
/* one or both is a NULL column? then don't convert... */
481+
if (otype == InvalidOid)
482+
{
483+
/* propagate a known type forward, if available */
484+
if (itype != InvalidOid)
485+
{
486+
((TargetEntry *)lfirst(prev_target))->resdom->restype = itype;
487+
}
488+
}
489+
else if (itype == InvalidOid)
490+
{
491+
}
492+
/* they don't match in type? then convert... */
493+
else if (itype != otype)
476494
{
477495
Node *expr;
478496

@@ -488,6 +506,7 @@ transformUnionClause(List *unionClause, List *targetlist)
488506
((TargetEntry *)lfirst(next_target))->expr = expr;
489507
((TargetEntry *)lfirst(next_target))->resdom->restype = otype;
490508
}
509+
491510
/* both are UNKNOWN? then evaluate as text... */
492511
else if (itype == UNKNOWNOID)
493512
{

0 commit comments

Comments
 (0)