0001-fixup-Implement-jsonpath-.number-.decimal-pr.patch.nocfbot

text/plain

Filename: 0001-fixup-Implement-jsonpath-.number-.decimal-pr.patch.nocfbot
Type: text/plain
Part: 0
Message: Re: More new SQL/JSON item methods
From 81e330a243d85dff7f64adf17815258e2764ea01 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 15 Jan 2024 14:11:36 +0100
Subject: [PATCH 1/2] fixup! Implement jsonpath .number(), .decimal([precision
 [, scale]]), .bigint(), and .integer() methods

---
 src/backend/utils/adt/jsonpath_gram.y | 43 +++++----------------------
 1 file changed, 8 insertions(+), 35 deletions(-)

diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y
index 24c31047ffd..9c06c3f6cb9 100644
--- a/src/backend/utils/adt/jsonpath_gram.y
+++ b/src/backend/utils/adt/jsonpath_gram.y
@@ -89,9 +89,9 @@ static bool makeItemLikeRegex(JsonPathParseItem *expr,
 %type	<value>		scalar_value path_primary expr array_accessor
 					any_path accessor_op key predicate delimited_predicate
 					index_elem starts_with_initial expr_or_predicate
-					datetime_template opt_datetime_template csv_elem
+					datetime_template opt_datetime_template
 
-%type	<elems>		accessor_expr csv_list opt_csv_list
+%type	<elems>		accessor_expr
 
 %type	<indexs>	index_list
 
@@ -252,39 +252,12 @@ accessor_op:
 	| '.' DATETIME_P '(' opt_datetime_template ')'
 									{ $$ = makeItemUnary(jpiDatetime, $4); }
 	| '?' '(' predicate ')'			{ $$ = makeItemUnary(jpiFilter, $3); }
-	| '.' DECIMAL_P '(' opt_csv_list ')'
-	{
-		if (list_length($4) == 0)
-			$$ = makeItemBinary(jpiDecimal, NULL, NULL);
-		else if (list_length($4) == 1)
-			$$ = makeItemBinary(jpiDecimal, linitial($4), NULL);
-		else if (list_length($4) == 2)
-			$$ = makeItemBinary(jpiDecimal, linitial($4), lsecond($4));
-		else
-			ereturn(escontext, false,
-					(errcode(ERRCODE_SYNTAX_ERROR),
-					 errmsg("invalid input syntax for type %s", "jsonpath"),
-					 errdetail(".decimal() can only have an optional precision[,scale].")));
-	}
-	;
-
-csv_elem:
-	INT_P
-		{ $$ = makeItemNumeric(&$1); }
-	| '+' INT_P %prec UMINUS
-		{ $$ = makeItemUnary(jpiPlus, makeItemNumeric(&$2)); }
-	| '-' INT_P %prec UMINUS
-		{ $$ = makeItemUnary(jpiMinus, makeItemNumeric(&$2)); }
-	;
-
-csv_list:
-	csv_elem						{ $$ = list_make1($1); }
-	| csv_list ',' csv_elem			{ $$ = lappend($1, $3); }
-	;
-
-opt_csv_list:
-	csv_list						{ $$ = $1; }
-	| /* EMPTY */					{ $$ = NULL; }
+	| '.' DECIMAL_P '(' ')'
+		{ $$ = makeItemBinary(jpiDecimal, NULL, NULL); }
+	| '.' DECIMAL_P '(' INT_P ')'
+		{ $$ = makeItemBinary(jpiDecimal, makeItemNumeric(&$4), NULL); }
+	| '.' DECIMAL_P '(' INT_P ',' INT_P ')'
+		{ $$ = makeItemBinary(jpiDecimal, makeItemNumeric(&$4), makeItemNumeric(&$6)); }
 	;
 
 datetime_template:
-- 
2.43.0