Arrange for CASE or UNION with only untyped literal constants as input
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Nov 2000 04:14:32 +0000 (04:14 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Nov 2000 04:14:32 +0000 (04:14 +0000)
to resolve the unknown constants as type TEXT.

src/backend/parser/parse_coerce.c

index 025a1d43195fdcbb94b56e04d7bd28ddb3200728..fb515432f06478c50e7173068b7c4c2541be65a6 100644 (file)
@@ -374,6 +374,22 @@ select_common_type(List *typeids, const char *context)
                        }
                }
        }
+
+       /*
+        * If all the inputs were UNKNOWN type --- ie, unknown-type literals ---
+        * then resolve as type TEXT.  This situation comes up with constructs
+        * like
+        *                      SELECT (CASE WHEN foo THEN 'bar' ELSE 'baz' END);
+        *                      SELECT 'foo' UNION SELECT 'bar';
+        * It might seem desirable to leave the construct's output type as
+        * UNKNOWN, but that really doesn't work, because we'd probably end up
+        * needing a runtime coercion from UNKNOWN to something else, and we
+        * usually won't have it.  We need to coerce the unknown literals while
+        * they are still literals, so a decision has to be made now.
+        */
+       if (ptype == UNKNOWNOID)
+               ptype = TEXTOID;
+
        return ptype;
 }