Skip to content

Commit 372e598

Browse files
committed
Arrange for CASE or UNION with only untyped literal constants as input
to resolve the unknown constants as type TEXT.
1 parent 9bbca2c commit 372e598

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/backend/parser/parse_coerce.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.47 2000/10/05 19:11:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.48 2000/11/09 04:14:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -374,6 +374,22 @@ select_common_type(List *typeids, const char *context)
374374
}
375375
}
376376
}
377+
378+
/*
379+
* If all the inputs were UNKNOWN type --- ie, unknown-type literals ---
380+
* then resolve as type TEXT. This situation comes up with constructs
381+
* like
382+
* SELECT (CASE WHEN foo THEN 'bar' ELSE 'baz' END);
383+
* SELECT 'foo' UNION SELECT 'bar';
384+
* It might seem desirable to leave the construct's output type as
385+
* UNKNOWN, but that really doesn't work, because we'd probably end up
386+
* needing a runtime coercion from UNKNOWN to something else, and we
387+
* usually won't have it. We need to coerce the unknown literals while
388+
* they are still literals, so a decision has to be made now.
389+
*/
390+
if (ptype == UNKNOWNOID)
391+
ptype = TEXTOID;
392+
377393
return ptype;
378394
}
379395

0 commit comments

Comments
 (0)