Skip to content

Commit 6bd69b9

Browse files
committed
Borrow json_validate() from PG16
The json_validate() function is borrowed from PG16 with minor changes. Because it does not exist in other versions of PG.
1 parent 3c8a3b6 commit 6bd69b9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/backend/utils/load/age_load.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
#include "postgres.h"
2121
#include "utils/json.h"
22+
#include "utils/jsonfuncs.h"
23+
#include "common/jsonapi.h"
2224

2325
#include "utils/load/ag_load_edges.h"
2426
#include "utils/load/ag_load_labels.h"
2527
#include "utils/load/age_load.h"
2628

2729
static agtype_value *csv_value_to_agtype_value(char *csv_val);
30+
static bool json_validate(text *json);
2831

2932
agtype *create_empty_agtype(void)
3033
{
@@ -43,6 +46,22 @@ agtype *create_empty_agtype(void)
4346
return out;
4447
}
4548

49+
/*
50+
* Validate JSON text.
51+
*
52+
* Note: this function is borrowed from PG16. It is simplified
53+
* by removing two parameters as they are not used in age.
54+
*/
55+
static bool json_validate(text *json)
56+
{
57+
JsonLexContext *lex = makeJsonLexContext(json, false);
58+
JsonParseErrorType result;
59+
60+
result = pg_parse_json(lex, &nullSemAction);
61+
62+
return result == JSON_SUCCESS;
63+
}
64+
4665
/*
4766
* Converts the given csv value to an agtype_value.
4867
*
@@ -56,7 +75,7 @@ static agtype_value *csv_value_to_agtype_value(char *csv_val)
5675
char *new_csv_val;
5776
agtype_value *res;
5877

59-
if (!json_validate(cstring_to_text(csv_val), false, false))
78+
if (!json_validate(cstring_to_text(csv_val)))
6079
{
6180
// wrap the string with double-quote
6281
int oldlen;

0 commit comments

Comments
 (0)