diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y
index a2acf2660f6..4d5837e2459 100644
--- a/src/backend/utils/adt/jsonpath_gram.y
+++ b/src/backend/utils/adt/jsonpath_gram.y
@@ -78,6 +78,13 @@ static bool makeItemTsMatch(JsonPathParseItem *doc,
 	JsonPathParseItem  *value;
 	JsonPathParseResult *result;
 	JsonPathItemType	optype;
+	struct
+	{
+		bool			has_tsconfig;
+		JsonPathString	tsconfig;
+		bool			has_tsqparser;
+		JsonPathString	tsqparser;
+	}				tsmatch_opts;
 	bool				boolean;
 	int					integer;
 }
@@ -100,6 +107,8 @@ static bool makeItemTsMatch(JsonPathParseItem *doc,
 					datetime_template opt_datetime_template csv_elem
 					datetime_precision opt_datetime_precision
 
+%type	<tsmatch_opts>	tsmatch_opts
+
 %type	<elems>		accessor_expr csv_list opt_csv_list
 
 %type	<indexs>	index_list
@@ -192,36 +201,44 @@ predicate:
 			YYABORT;
 		$$ = jppitem;
 	}
-	| expr TSMATCH_P STRING_P
+	| expr TSMATCH_P STRING_P tsmatch_opts
 	{
 		JsonPathParseItem *jppitem;
-		/* Pass NULL for tsconfig (3rd) and NULL for tsquery_parser (4th) */
-		if (! makeItemTsMatch($1, &$3, NULL, NULL, &jppitem, escontext))
-		   YYABORT;
+
+		if (! makeItemTsMatch($1, &$3,
+							  $4.has_tsconfig ? &$4.tsconfig : NULL,
+							  $4.has_tsqparser ? &$4.tsqparser : NULL,
+							  &jppitem, escontext))
+			YYABORT;
+
 		$$ = jppitem;
 	}
-	| expr TSMATCH_P STRING_P TSCONFIG_P STRING_P
+	;
+
+tsmatch_opts:
+	/* EMPTY */
 	{
-		JsonPathParseItem *jppitem;
-		/* Pass NULL for tsquery_parser (4th) */
-		if (! makeItemTsMatch($1, &$3, &$5, NULL, &jppitem, escontext))
-		   YYABORT;
-		$$ = jppitem;
+		$$.has_tsconfig = false;
+		$$.has_tsqparser = false;
 	}
-	| expr TSMATCH_P STRING_P TSQUERYPARSER_P STRING_P
+	| TSCONFIG_P STRING_P
 	{
-		JsonPathParseItem *jppitem;
-		/* Pass NULL for tsconfig (3rd) */
-		if (! makeItemTsMatch($1, &$3, NULL, &$5, &jppitem, escontext))
-		   YYABORT;
-		$$ = jppitem;
+		$$.has_tsconfig = true;
+		$$.tsconfig = $2;
+		$$.has_tsqparser = false;
 	}
-	| expr TSMATCH_P STRING_P TSCONFIG_P STRING_P TSQUERYPARSER_P STRING_P
+	| TSQUERYPARSER_P STRING_P
 	{
-		JsonPathParseItem *jppitem;
-		if (! makeItemTsMatch($1, &$3, &$5, &$7, &jppitem, escontext))
-		   YYABORT;
-		$$ = jppitem;
+		$$.has_tsconfig = false;
+		$$.has_tsqparser = true;
+		$$.tsqparser = $2;
+	}
+	| TSCONFIG_P STRING_P TSQUERYPARSER_P STRING_P
+	{
+		$$.has_tsconfig = true;
+		$$.tsconfig = $2;
+		$$.has_tsqparser = true;
+		$$.tsqparser = $4;
 	}
 	;
 
@@ -762,7 +779,7 @@ makeItemTsMatch(JsonPathParseItem *doc,
 		{
 			 ereport(ERROR,
 					 (errcode(ERRCODE_SYNTAX_ERROR),
-					  errmsg("invalid tsquery_parser value: \"%s\"", tsquery_parser->val),
+					  errmsg("invalid tsquery_parser value: \"%.*s\"", (int) tsquery_parser->len, tsquery_parser->val),
 					  errhint("Valid values are \"pl\", \"ph\", and \"w\".")));
 		}
 
