MCPcopy Create free account
hub / github.com/apache/cloudberry / plpgsql_recognize_err_condition

Function plpgsql_recognize_err_condition

src/pl/plpgsql/src/pl_comp.c:2248–2275  ·  view source on GitHub ↗

* plpgsql_recognize_err_condition * Check condition name and translate it to SQLSTATE. * * Note: there are some cases where the same condition name has multiple * entries in the table. We arbitrarily return the first match. */

Source from the content-addressed store, hash-verified

2246 * entries in the table. We arbitrarily return the first match.
2247 */
2248int
2249plpgsql_recognize_err_condition(const char *condname, bool allow_sqlstate)
2250{
2251 int i;
2252
2253 if (allow_sqlstate)
2254 {
2255 if (strlen(condname) == 5 &&
2256 strspn(condname, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 5)
2257 return MAKE_SQLSTATE(condname[0],
2258 condname[1],
2259 condname[2],
2260 condname[3],
2261 condname[4]);
2262 }
2263
2264 for (i = 0; exception_label_map[i].label != NULL; i++)
2265 {
2266 if (strcmp(condname, exception_label_map[i].label) == 0)
2267 return exception_label_map[i].sqlerrstate;
2268 }
2269
2270 ereport(ERROR,
2271 (errcode(ERRCODE_UNDEFINED_OBJECT),
2272 errmsg("unrecognized exception condition \"%s\"",
2273 condname)));
2274 return 0; /* keep compiler quiet */
2275}
2276
2277/*
2278 * plpgsql_parse_err_condition

Callers 1

exec_stmt_raiseFunction · 0.85

Calls 2

errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected