diff options
| author | Andrew Dunstan | 2022-03-03 18:15:13 +0000 |
|---|---|---|
| committer | Andrew Dunstan | 2022-03-30 20:30:37 +0000 |
| commit | 606948b058dc16bce494270eea577011a602810e (patch) | |
| tree | dad8b48083701f5560b6696b6ad770a3c6af84d3 /src/include/nodes | |
| parent | 8e053dc6dfbee4ae412e98ad73cfd4662d7453ac (diff) | |
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
Diffstat (limited to 'src/include/nodes')
| -rw-r--r-- | src/include/nodes/nodes.h | 3 | ||||
| -rw-r--r-- | src/include/nodes/parsenodes.h | 35 | ||||
| -rw-r--r-- | src/include/nodes/primnodes.h | 5 |
3 files changed, 42 insertions, 1 deletions
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index d48147abeef..a56b85fe743 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -205,6 +205,9 @@ typedef enum NodeTag T_JsonFormat, T_JsonReturning, T_JsonValueExpr, + T_JsonParseExpr, + T_JsonScalarExpr, + T_JsonSerializeExpr, T_JsonConstructorExpr, T_JsonExpr, T_JsonCoercion, diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 0ff4ba08846..c24fc26da17 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1677,6 +1677,41 @@ typedef struct JsonKeyValue } JsonKeyValue; /* + * JsonParseExpr - + * untransformed representation of JSON() + */ +typedef struct JsonParseExpr +{ + NodeTag type; + JsonValueExpr *expr; /* string expression */ + bool unique_keys; /* WITH UNIQUE KEYS? */ + int location; /* token location, or -1 if unknown */ +} JsonParseExpr; + +/* + * JsonScalarExpr - + * untransformed representation of JSON_SCALAR() + */ +typedef struct JsonScalarExpr +{ + NodeTag type; + Expr *expr; /* scalar expression */ + int location; /* token location, or -1 if unknown */ +} JsonScalarExpr; + +/* + * JsonSerializeExpr - + * untransformed representation of JSON_SERIALIZE() function + */ +typedef struct JsonSerializeExpr +{ + NodeTag type; + JsonValueExpr *expr; /* json value expression */ + JsonOutput *output; /* RETURNING clause, if specified */ + int location; /* token location, or -1 if unknown */ +} JsonSerializeExpr; + +/* * JsonObjectConstructor - * untransformed representation of JSON_OBJECT() constructor */ diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 7ebe868af91..439a16aa62e 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -1339,7 +1339,10 @@ typedef enum JsonConstructorType JSCTOR_JSON_OBJECT = 1, JSCTOR_JSON_ARRAY = 2, JSCTOR_JSON_OBJECTAGG = 3, - JSCTOR_JSON_ARRAYAGG = 4 + JSCTOR_JSON_ARRAYAGG = 4, + JSCTOR_JSON_SCALAR = 5, + JSCTOR_JSON_SERIALIZE = 6, + JSCTOR_JSON_PARSE = 7 } JsonConstructorType; /* |
