1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

SQL JSON functions

This Patch introduces three SQL standard JSON functions:

JSON() (incorrectly mentioned in my commit message for f4fb45d15c)
JSON_SCALAR()
JSON_SERIALIZE()

JSON() produces json values from text, bytea, json or jsonb values, and
has facilitites for handling duplicate keys.
JSON_SCALAR() produces a json value from any scalar sql value, including
json and jsonb.
JSON_SERIALIZE() produces text or bytea from input which containis or
represents json or jsonb;

For the most part these functions don't add any significant new
capabilities, but they will be of use to users wanting standard
compliant JSON handling.

Nikita Glukhov

Reviewers have included (in no particular order) Andres Freund, Alexander
Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zihong Yu,
Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby.

Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru
This commit is contained in:
Andrew Dunstan
2022-03-03 13:15:13 -05:00
parent 8e053dc6df
commit 606948b058
22 changed files with 880 additions and 82 deletions

View File

@ -2345,6 +2345,50 @@ _copyJsonValueExpr(const JsonValueExpr *from)
return newnode;
}
/*
* _copyJsonParseExpr
*/
static JsonParseExpr *
_copyJsonParseExpr(const JsonParseExpr *from)
{
JsonParseExpr *newnode = makeNode(JsonParseExpr);
COPY_NODE_FIELD(expr);
COPY_SCALAR_FIELD(unique_keys);
COPY_LOCATION_FIELD(location);
return newnode;
}
/*
* _copyJsonScalarExpr
*/
static JsonScalarExpr *
_copyJsonScalarExpr(const JsonScalarExpr *from)
{
JsonScalarExpr *newnode = makeNode(JsonScalarExpr);
COPY_NODE_FIELD(expr);
COPY_LOCATION_FIELD(location);
return newnode;
}
/*
* _copyJsonSerializeExpr
*/
static JsonSerializeExpr *
_copyJsonSerializeExpr(const JsonSerializeExpr *from)
{
JsonSerializeExpr *newnode = makeNode(JsonSerializeExpr);
COPY_NODE_FIELD(expr);
COPY_NODE_FIELD(output);
COPY_LOCATION_FIELD(location);
return newnode;
}
/*
* _copyJsonConstructorExpr
*/
@ -5744,6 +5788,15 @@ copyObjectImpl(const void *from)
case T_JsonValueExpr:
retval = _copyJsonValueExpr(from);
break;
case T_JsonParseExpr:
retval = _copyJsonParseExpr(from);
break;
case T_JsonScalarExpr:
retval = _copyJsonScalarExpr(from);
break;
case T_JsonSerializeExpr:
retval = _copyJsonSerializeExpr(from);
break;
case T_JsonKeyValue:
retval = _copyJsonKeyValue(from);
break;