mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +03:00
SQL/JSON query functions
This introduces the SQL/JSON functions for querying JSON data using jsonpath expressions. The functions are: JSON_EXISTS() JSON_QUERY() JSON_VALUE() All of these functions only operate on jsonb. The workaround for now is to cast the argument to jsonb. JSON_EXISTS() tests if the jsonpath expression applied to the jsonb value yields any values. JSON_VALUE() must return a single value, and an error occurs if it tries to return multiple values. JSON_QUERY() must return a json object or array, and there are various WRAPPER options for handling scalar or multi-value results. Both these functions have options for handling EMPTY and ERROR conditions. 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:
@ -1808,6 +1808,64 @@ _outJsonIsPredicate(StringInfo str, const JsonIsPredicate *node)
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
_outJsonBehavior(StringInfo str, const JsonBehavior *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("JSONBEHAVIOR");
|
||||
|
||||
WRITE_ENUM_FIELD(btype, JsonBehaviorType);
|
||||
WRITE_NODE_FIELD(default_expr);
|
||||
}
|
||||
|
||||
static void
|
||||
_outJsonExpr(StringInfo str, const JsonExpr *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("JSONEXPR");
|
||||
|
||||
WRITE_ENUM_FIELD(op, JsonExprOp);
|
||||
WRITE_NODE_FIELD(formatted_expr);
|
||||
WRITE_NODE_FIELD(result_coercion);
|
||||
WRITE_NODE_FIELD(format);
|
||||
WRITE_NODE_FIELD(path_spec);
|
||||
WRITE_NODE_FIELD(passing_values);
|
||||
WRITE_NODE_FIELD(passing_names);
|
||||
WRITE_NODE_FIELD(returning);
|
||||
WRITE_NODE_FIELD(on_error);
|
||||
WRITE_NODE_FIELD(on_empty);
|
||||
WRITE_NODE_FIELD(coercions);
|
||||
WRITE_ENUM_FIELD(wrapper, JsonWrapper);
|
||||
WRITE_BOOL_FIELD(omit_quotes);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
_outJsonCoercion(StringInfo str, const JsonCoercion *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("JSONCOERCION");
|
||||
|
||||
WRITE_NODE_FIELD(expr);
|
||||
WRITE_BOOL_FIELD(via_populate);
|
||||
WRITE_BOOL_FIELD(via_io);
|
||||
WRITE_OID_FIELD(collation);
|
||||
}
|
||||
|
||||
static void
|
||||
_outJsonItemCoercions(StringInfo str, const JsonItemCoercions *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("JSONITEMCOERCIONS");
|
||||
|
||||
WRITE_NODE_FIELD(null);
|
||||
WRITE_NODE_FIELD(string);
|
||||
WRITE_NODE_FIELD(numeric);
|
||||
WRITE_NODE_FIELD(boolean);
|
||||
WRITE_NODE_FIELD(date);
|
||||
WRITE_NODE_FIELD(time);
|
||||
WRITE_NODE_FIELD(timetz);
|
||||
WRITE_NODE_FIELD(timestamp);
|
||||
WRITE_NODE_FIELD(timestamptz);
|
||||
WRITE_NODE_FIELD(composite);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Stuff from pathnodes.h.
|
||||
@ -4644,6 +4702,18 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_JsonIsPredicate:
|
||||
_outJsonIsPredicate(str, obj);
|
||||
break;
|
||||
case T_JsonBehavior:
|
||||
_outJsonBehavior(str, obj);
|
||||
break;
|
||||
case T_JsonExpr:
|
||||
_outJsonExpr(str, obj);
|
||||
break;
|
||||
case T_JsonCoercion:
|
||||
_outJsonCoercion(str, obj);
|
||||
break;
|
||||
case T_JsonItemCoercions:
|
||||
_outJsonItemCoercions(str, obj);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
|
Reference in New Issue
Block a user