diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-12-25 14:32:02 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-12-25 14:32:30 -0500 |
commit | 442e25d2485b1ecf3357725acee995a1c349163d (patch) | |
tree | 74d5d9f38f4a7e242cc87bcad98a17804a320939 /src/backend/utils/adt/enum.c | |
parent | 361ec4368b1da252e031e2ee8bce366bce5f72b2 (diff) |
Convert enum_in() to report errors softly.
I missed this in my initial survey, probably because I examined
the contents of pg_type in the postgres database, which lacks
any enumerated types.
Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/enum.c')
-rw-r--r-- | src/backend/utils/adt/enum.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/utils/adt/enum.c b/src/backend/utils/adt/enum.c index 0cc7a6d8ad0..431a89c9ab2 100644 --- a/src/backend/utils/adt/enum.c +++ b/src/backend/utils/adt/enum.c @@ -110,12 +110,13 @@ enum_in(PG_FUNCTION_ARGS) { char *name = PG_GETARG_CSTRING(0); Oid enumtypoid = PG_GETARG_OID(1); + Node *escontext = fcinfo->context; Oid enumoid; HeapTuple tup; /* must check length to prevent Assert failure within SearchSysCache */ if (strlen(name) >= NAMEDATALEN) - ereport(ERROR, + ereturn(escontext, (Datum) 0, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input value for enum %s: \"%s\"", format_type_be(enumtypoid), @@ -125,13 +126,18 @@ enum_in(PG_FUNCTION_ARGS) ObjectIdGetDatum(enumtypoid), CStringGetDatum(name)); if (!HeapTupleIsValid(tup)) - ereport(ERROR, + ereturn(escontext, (Datum) 0, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input value for enum %s: \"%s\"", format_type_be(enumtypoid), name))); - /* check it's safe to use in SQL */ + /* + * Check it's safe to use in SQL. Perhaps we should take the trouble to + * report "unsafe use" softly; but it's unclear that it's worth the + * trouble, or indeed that that is a legitimate bad-input case at all + * rather than an implementation shortcoming. + */ check_safe_enum_use(tup); /* |