From 1f3a021730be98b880d94cabbe21de7e4d8136f5 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Mon, 27 Jan 2020 11:03:21 -0500 Subject: Adjust pg_parse_json() so that it does not directly ereport(). Instead, it now returns a value indicating either success or the type of error which occurred. The old behavior is still available by calling pg_parse_json_or_ereport(). If the new interface is used, an error can be thrown by passing the return value of pg_parse_json() to json_ereport_error(). pg_parse_json() can still elog() in can't-happen cases, but it seems like that issue is best handled separately. Adjust json_lex() and json_count_array_elements() to return an error code, too. This is all in preparation for making the backend's json parser available to frontend code. Reviewed and/or tested by Mark Dilger and Andrew Dunstan. Discussion: http://postgr.es/m/CA+TgmoYfOXhd27MUDGioVh6QtpD0C1K-f6ObSA10AWiHBAL5bA@mail.gmail.com --- src/backend/utils/adt/jsonb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/adt/jsonb.c') diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c index c4a4ec78b0e..83d7f68b821 100644 --- a/src/backend/utils/adt/jsonb.c +++ b/src/backend/utils/adt/jsonb.c @@ -272,7 +272,7 @@ jsonb_from_cstring(char *json, int len) sem.scalar = jsonb_in_scalar; sem.object_field_start = jsonb_in_object_field_start; - pg_parse_json(lex, &sem); + pg_parse_json_or_ereport(lex, &sem); /* after parsing, the item member has the composed jsonb structure */ PG_RETURN_POINTER(JsonbValueToJsonb(state.res)); @@ -860,7 +860,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result, sem.scalar = jsonb_in_scalar; sem.object_field_start = jsonb_in_object_field_start; - pg_parse_json(lex, &sem); + pg_parse_json_or_ereport(lex, &sem); } break; -- cgit v1.2.3