<row>
<entry role="func_table_entry"><para role="func_signature">
- <replaceable>number</replaceable> <literal>.</literal> <literal>abs()</literal>
+ <replaceable>number</replaceable> <literal>.</literal> <literal>ceiling()</literal>
<returnvalue><replaceable>number</replaceable></returnvalue>
</para>
<para>
- Absolute value of the given number
+ Nearest integer greater than or equal to the given number
</para>
<para>
- <literal>jsonb_path_query('{"z": -0.3}', '$.z.abs()')</literal>
- <returnvalue>0.3</returnvalue>
+ <literal>jsonb_path_query('{"h": 1.3}', '$.h.ceiling()')</literal>
+ <returnvalue>2</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
- <replaceable>number</replaceable> <literal>.</literal> <literal>ceiling()</literal>
+ <replaceable>number</replaceable> <literal>.</literal> <literal>floor()</literal>
<returnvalue><replaceable>number</replaceable></returnvalue>
</para>
<para>
- Nearest integer greater than or equal to the given number
+ Nearest integer less than or equal to the given number
</para>
<para>
- <literal>jsonb_path_query('{"h": 1.3}', '$.h.ceiling()')</literal>
- <returnvalue>2</returnvalue>
+ <literal>jsonb_path_query('{"h": 1.7}', '$.h.floor()')</literal>
+ <returnvalue>1</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
- <replaceable>number</replaceable> <literal>.</literal> <literal>floor()</literal>
+ <replaceable>number</replaceable> <literal>.</literal> <literal>abs()</literal>
<returnvalue><replaceable>number</replaceable></returnvalue>
</para>
<para>
- Nearest integer less than or equal to the given number
+ Absolute value of the given number
</para>
<para>
- <literal>jsonb_path_query('{"h": 1.7}', '$.h.floor()')</literal>
- <returnvalue>1</returnvalue>
+ <literal>jsonb_path_query('{"z": -0.3}', '$.z.abs()')</literal>
+ <returnvalue>0.3</returnvalue>
</para></entry>
</row>
break;
case jpiType:
case jpiSize:
- case jpiDouble:
case jpiAbs:
- case jpiCeiling:
case jpiFloor:
+ case jpiCeiling:
+ case jpiDouble:
case jpiKeyValue:
break;
default:
if (printBracketes)
appendStringInfoChar(buf, ')');
break;
+ case jpiPlus:
+ case jpiMinus:
+ if (printBracketes)
+ appendStringInfoChar(buf, '(');
+ appendStringInfoChar(buf, v->type == jpiPlus ? '+' : '-');
+ jspGetArg(v, &elem);
+ printJsonPathItem(buf, &elem, false,
+ operationPriority(elem.type) <=
+ operationPriority(v->type));
+ if (printBracketes)
+ appendStringInfoChar(buf, ')');
+ break;
case jpiFilter:
appendStringInfoString(buf, "?(");
jspGetArg(v, &elem);
v->content.anybounds.first,
v->content.anybounds.last);
break;
- case jpiPlus:
- case jpiMinus:
- if (printBracketes)
- appendStringInfoChar(buf, '(');
- appendStringInfoChar(buf, v->type == jpiPlus ? '+' : '-');
- jspGetArg(v, &elem);
- printJsonPathItem(buf, &elem, false,
- operationPriority(elem.type) <=
- operationPriority(v->type));
- if (printBracketes)
- appendStringInfoChar(buf, ')');
- break;
case jpiType:
appendStringInfoString(buf, ".type()");
break;
case jpiSize:
appendStringInfoString(buf, ".size()");
break;
- case jpiDouble:
- appendStringInfoString(buf, ".double()");
- break;
case jpiAbs:
appendStringInfoString(buf, ".abs()");
break;
+ case jpiFloor:
+ appendStringInfoString(buf, ".floor()");
+ break;
case jpiCeiling:
appendStringInfoString(buf, ".ceiling()");
break;
- case jpiFloor:
- appendStringInfoString(buf, ".floor()");
+ case jpiDouble:
+ appendStringInfoString(buf, ".double()");
break;
case jpiDatetime:
appendStringInfoString(buf, ".datetime(");
return "<=";
case jpiGreaterOrEqual:
return ">=";
- case jpiAdd:
case jpiPlus:
+ case jpiAdd:
return "+";
- case jpiSub:
case jpiMinus:
+ case jpiSub:
return "-";
case jpiMul:
return "*";
return "/";
case jpiMod:
return "%";
+ case jpiStartsWith:
+ return "starts with";
+ case jpiLikeRegex:
+ return "like_regex";
case jpiType:
return "type";
case jpiSize:
return "size";
+ case jpiKeyValue:
+ return "keyvalue";
case jpiDouble:
return "double";
case jpiAbs:
return "abs";
- case jpiCeiling:
- return "ceiling";
case jpiFloor:
return "floor";
+ case jpiCeiling:
+ return "ceiling";
case jpiDatetime:
return "datetime";
- case jpiKeyValue:
- return "keyvalue";
- case jpiStartsWith:
- return "starts with";
- case jpiLikeRegex:
- return "like_regex";
default:
elog(ERROR, "unrecognized jsonpath item type: %d", type);
return NULL;
case jpiAnyKey:
case jpiType:
case jpiSize:
- case jpiDouble:
case jpiAbs:
- case jpiCeiling:
case jpiFloor:
+ case jpiCeiling:
+ case jpiDouble:
case jpiKeyValue:
case jpiLast:
break;
case jpiNot:
case jpiExists:
case jpiIsUnknown:
- case jpiFilter:
case jpiPlus:
case jpiMinus:
+ case jpiFilter:
case jpiDatetime:
read_int32(v->content.arg, base, pos);
break;
v->type == jpiRoot ||
v->type == jpiVariable ||
v->type == jpiLast ||
+ v->type == jpiAdd ||
+ v->type == jpiSub ||
+ v->type == jpiMul ||
+ v->type == jpiDiv ||
+ v->type == jpiMod ||
+ v->type == jpiPlus ||
+ v->type == jpiMinus ||
v->type == jpiEqual ||
v->type == jpiNotEqual ||
v->type == jpiGreater ||
v->type == jpiOr ||
v->type == jpiNot ||
v->type == jpiIsUnknown ||
- v->type == jpiAdd ||
- v->type == jpiPlus ||
- v->type == jpiSub ||
- v->type == jpiMinus ||
- v->type == jpiMul ||
- v->type == jpiDiv ||
- v->type == jpiMod ||
v->type == jpiType ||
v->type == jpiSize ||
- v->type == jpiDouble ||
v->type == jpiAbs ||
- v->type == jpiCeiling ||
v->type == jpiFloor ||
+ v->type == jpiCeiling ||
+ v->type == jpiDouble ||
v->type == jpiDatetime ||
v->type == jpiKeyValue ||
v->type == jpiStartsWith ||
}
break;
+ case jpiAdd:
+ return executeBinaryArithmExpr(cxt, jsp, jb,
+ numeric_add_opt_error, found);
+
+ case jpiSub:
+ return executeBinaryArithmExpr(cxt, jsp, jb,
+ numeric_sub_opt_error, found);
+
+ case jpiMul:
+ return executeBinaryArithmExpr(cxt, jsp, jb,
+ numeric_mul_opt_error, found);
+
+ case jpiDiv:
+ return executeBinaryArithmExpr(cxt, jsp, jb,
+ numeric_div_opt_error, found);
+
+ case jpiMod:
+ return executeBinaryArithmExpr(cxt, jsp, jb,
+ numeric_mod_opt_error, found);
+
+ case jpiPlus:
+ return executeUnaryArithmExpr(cxt, jsp, jb, NULL, found);
+
+ case jpiMinus:
+ return executeUnaryArithmExpr(cxt, jsp, jb, numeric_uminus,
+ found);
+
case jpiFilter:
{
JsonPathBool st;
}
break;
- case jpiAdd:
- return executeBinaryArithmExpr(cxt, jsp, jb,
- numeric_add_opt_error, found);
-
- case jpiPlus:
- return executeUnaryArithmExpr(cxt, jsp, jb, NULL, found);
-
- case jpiSub:
- return executeBinaryArithmExpr(cxt, jsp, jb,
- numeric_sub_opt_error, found);
-
- case jpiMinus:
- return executeUnaryArithmExpr(cxt, jsp, jb, numeric_uminus,
- found);
-
- case jpiMul:
- return executeBinaryArithmExpr(cxt, jsp, jb,
- numeric_mul_opt_error, found);
-
- case jpiDiv:
- return executeBinaryArithmExpr(cxt, jsp, jb,
- numeric_div_opt_error, found);
-
- case jpiMod:
- return executeBinaryArithmExpr(cxt, jsp, jb,
- numeric_mod_opt_error, found);
-
case jpiType:
{
JsonbValue *jbv = palloc(sizeof(*jbv));
}
break;
+ case jpiAbs:
+ return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_abs,
+ found);
+
+ case jpiFloor:
+ return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_floor,
+ found);
+
+ case jpiCeiling:
+ return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_ceil,
+ found);
+
case jpiDouble:
{
JsonbValue jbv;
}
break;
- case jpiAbs:
- return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_abs,
- found);
-
- case jpiCeiling:
- return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_ceil,
- found);
-
- case jpiFloor:
- return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_floor,
- found);
-
case jpiDatetime:
if (unwrap && JsonbType(jb) == jbvArray)
return executeItemUnwrapTargetArray(cxt, jsp, jb, found, false);
%token <str> OR_P AND_P NOT_P
%token <str> LESS_P LESSEQUAL_P EQUAL_P NOTEQUAL_P GREATEREQUAL_P GREATER_P
%token <str> ANY_P STRICT_P LAX_P LAST_P STARTS_P WITH_P LIKE_REGEX_P FLAG_P
-%token <str> TYPE_P SIZE_P DOUBLE_P ABS_P CEILING_P FLOOR_P KEYVALUE_P
+%token <str> ABS_P SIZE_P TYPE_P FLOOR_P DOUBLE_P CEILING_P KEYVALUE_P
%token <str> DATETIME_P
%type <result> result
expr:
accessor_expr { $$ = makeItemList($1); }
| '(' expr ')' { $$ = $2; }
- | expr '+' expr { $$ = makeItemBinary(jpiAdd, $1, $3); }
| '+' expr %prec UMINUS { $$ = makeItemUnary(jpiPlus, $2); }
- | expr '-' expr { $$ = makeItemBinary(jpiSub, $1, $3); }
| '-' expr %prec UMINUS { $$ = makeItemUnary(jpiMinus, $2); }
+ | expr '+' expr { $$ = makeItemBinary(jpiAdd, $1, $3); }
+ | expr '-' expr { $$ = makeItemBinary(jpiSub, $1, $3); }
| expr '*' expr { $$ = makeItemBinary(jpiMul, $1, $3); }
| expr '/' expr { $$ = makeItemBinary(jpiDiv, $1, $3); }
| expr '%' expr { $$ = makeItemBinary(jpiMod, $1, $3); }
| EXISTS_P
| STRICT_P
| LAX_P
- | LAST_P
- | FLAG_P
- | TYPE_P
+ | ABS_P
| SIZE_P
+ | TYPE_P
+ | FLOOR_P
| DOUBLE_P
- | ABS_P
| CEILING_P
- | FLOOR_P
| DATETIME_P
| KEYVALUE_P
+ | LAST_P
| STARTS_P
| WITH_P
| LIKE_REGEX_P
+ | FLAG_P
;
method:
- TYPE_P { $$ = jpiType; }
+ ABS_P { $$ = jpiAbs; }
| SIZE_P { $$ = jpiSize; }
+ | TYPE_P { $$ = jpiType; }
+ | FLOOR_P { $$ = jpiFloor; }
| DOUBLE_P { $$ = jpiDouble; }
- | ABS_P { $$ = jpiAbs; }
| CEILING_P { $$ = jpiCeiling; }
- | FLOOR_P { $$ = jpiFloor; }
| KEYVALUE_P { $$ = jpiKeyValue; }
;
%%
jpiGreater, /* expr > expr */
jpiLessOrEqual, /* expr <= expr */
jpiGreaterOrEqual, /* expr >= expr */
+ jpiAdd, /* expr + expr */
+ jpiSub, /* expr - expr */
+ jpiMul, /* expr * expr */
+ jpiDiv, /* expr / expr */
+ jpiMod, /* expr % expr */
+ jpiPlus, /* + expr */
+ jpiMinus, /* - expr */
jpiAnyArray, /* [*] */
jpiAnyKey, /* .* */
jpiIndexArray, /* [subscript, ...] */
jpiVariable, /* $variable */
jpiFilter, /* ? (predicate) */
jpiExists, /* EXISTS (expr) predicate */
-
- /*
- * For better maintainability or readability, keep the order of the below
- * jsonpath Operators and Methods at the other places, like in the
- * documentation, switch() cases, keywords list, etc., too.
- */
- jpiAdd, /* expr + expr */
- jpiPlus, /* + expr */
- jpiSub, /* expr - expr */
- jpiMinus, /* - expr */
- jpiMul, /* expr * expr */
- jpiDiv, /* expr / expr */
- jpiMod, /* expr % expr */
jpiType, /* .type() item method */
jpiSize, /* .size() item method */
- jpiDouble, /* .double() item method */
jpiAbs, /* .abs() item method */
- jpiCeiling, /* .ceiling() item method */
jpiFloor, /* .floor() item method */
+ jpiCeiling, /* .ceiling() item method */
+ jpiDouble, /* .double() item method */
jpiDatetime, /* .datetime() item method */
jpiKeyValue, /* .keyvalue() item method */
-
jpiSubscript, /* array subscript: 'expr' or 'expr TO expr' */
jpiLast, /* LAST array subscript */
jpiStartsWith, /* STARTS WITH predicate */