Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f3a021

Browse files
committed
Adjust pg_parse_json() so that it does not directly ereport().
Instead, it now returns a value indicating either success or thetype of error which occurred. The old behavior is still availableby calling pg_parse_json_or_ereport(). If the new interface isused, an error can be thrown by passing the return value ofpg_parse_json() to json_ereport_error().pg_parse_json() can still elog() in can't-happen cases, but itseems like that issue is best handled separately.Adjust json_lex() and json_count_array_elements() to return anerror code, too.This is all in preparation for making the backend's json parseravailable to frontend code.Reviewed and/or tested by Mark Dilger and Andrew Dunstan.Discussion:http://postgr.es/m/CA+TgmoYfOXhd27MUDGioVh6QtpD0C1K-f6ObSA10AWiHBAL5bA@mail.gmail.com
1 parent3e4818e commit1f3a021

File tree

5 files changed

+342
-283
lines changed

5 files changed

+342
-283
lines changed

‎src/backend/utils/adt/json.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ json_in(PG_FUNCTION_ARGS)
8181

8282
/* validate it */
8383
lex=makeJsonLexContext(result, false);
84-
pg_parse_json(lex,&nullSemAction);
84+
pg_parse_json_or_ereport(lex,&nullSemAction);
8585

8686
/* Internal representation is the same as text, for now */
8787
PG_RETURN_TEXT_P(result);
@@ -128,7 +128,7 @@ json_recv(PG_FUNCTION_ARGS)
128128

129129
/* Validate it. */
130130
lex=makeJsonLexContextCstringLen(str,nbytes, false);
131-
pg_parse_json(lex,&nullSemAction);
131+
pg_parse_json_or_ereport(lex,&nullSemAction);
132132

133133
PG_RETURN_TEXT_P(cstring_to_text_with_len(str,nbytes));
134134
}
@@ -1337,12 +1337,15 @@ json_typeof(PG_FUNCTION_ARGS)
13371337
JsonLexContext*lex;
13381338
JsonTokenTypetok;
13391339
char*type;
1340+
JsonParseErrorTyperesult;
13401341

13411342
json=PG_GETARG_TEXT_PP(0);
13421343
lex=makeJsonLexContext(json, false);
13431344

13441345
/* Lex exactly one token from the input and check its type. */
1345-
json_lex(lex);
1346+
result=json_lex(lex);
1347+
if (result!=JSON_SUCCESS)
1348+
json_ereport_error(result,lex);
13461349
tok=lex->token_type;
13471350
switch (tok)
13481351
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp