From 79a09ba63178db192937f689aaebefc1360ca0bf Mon Sep 17 00:00:00 2001 From: Florents Tselai Date: Mon, 26 Jan 2026 19:17:41 +0200 Subject: [PATCH v1] Add tsmatch JSONPath operator for granular Full Text Search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch introduces the tsmatch boolean operator to the JSONPath engine. By integrating FTS natively into path expressions, this operator allows for high-precision filtering of nested JSONB structures— solving issues with structural ambiguity and query complexity. Currently, users must choose between two suboptimal paths for searching nested JSON: - Imprecise Global Indexing jsonb_to_tsvector aggregates text into a flat vector. This ignores JSON boundaries, leading to false positives when the same key (e.g., "body") appears in different contexts (e.g., a "Product Description" vs. a "Customer Review"). - Complex SQL Workarounds Achieving 100% precision requires "exploding" the document via jsonb_array_elementsand LATERAL joins. This leads to verbose SQL and high memory overhead from generating intermediate heap tuples. One of the most significant advantages of tsmatch is its ability to participate in multi-condition predicates within the same JSON object - something jsonb_to_tsvector cannot do. SELECT jsonb_path_query(doc, '$.comments[*] ? (@.user == "Alice" && @.body tsmatch "performance")'); In a flat vector, the association between "Alice" and "performance" is lost. tsmatch preserves this link by evaluating the FTS predicate in-place during path traversal. While the SQL/JSON standard (ISO/IEC 9075-2) does not explicitly define an FTS operator, tsmatch is architecturally modeled after the standard-defined like_regex. The implementation follows the like_regex precedent: it is a non-indexable predicate that relies on GIN path-matching for pruning and heap re-checks for precision. Caching is scoped to the JsonPathExecContext, ensuring 'compile-once' efficiency per execution without violating the stability requirements of prepared statements. This initial implementation uses plainto_tsquery. However, the grammar is designed to support a "mode" flag (similar to like_regex flags) in future iterations to toggle between to_tsquery, websearch_to_tsquery, and phraseto_tsquery. --- src/backend/utils/adt/jsonpath.c | 90 ++++++++++++++++++++ src/backend/utils/adt/jsonpath_exec.c | 88 ++++++++++++++++++- src/backend/utils/adt/jsonpath_gram.y | 66 +++++++++++++- src/backend/utils/adt/jsonpath_scan.l | 2 + src/include/utils/jsonpath.h | 15 ++++ src/test/regress/expected/jsonb_jsonpath.out | 46 ++++++++++ src/test/regress/expected/jsonpath.out | 42 +++++++++ src/test/regress/sql/jsonb_jsonpath.sql | 8 ++ src/test/regress/sql/jsonpath.sql | 14 +++ 9 files changed, 369 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/jsonpath.c b/src/backend/utils/adt/jsonpath.c index 18a8046d6cf..87c26f7adcf 100644 --- a/src/backend/utils/adt/jsonpath.c +++ b/src/backend/utils/adt/jsonpath.c @@ -349,6 +349,50 @@ flattenJsonPathParseItem(StringInfo buf, int *result, struct Node *escontext, *(int32 *) (buf->data + offs) = chld - pos; } break; + case jpiTsMatch: + { + int32 expr_off; + int32 config_off; + + expr_off = reserveSpaceForItemPointer(buf); /* Slot for '@' */ + config_off = reserveSpaceForItemPointer(buf); /* Slot for 'tsconfig' */ + + /* Write the tsquery String */ + appendBinaryStringInfo(buf, + &item->value.tsmatch.tsquerylen, + sizeof(item->value.tsmatch.tsquerylen)); + appendBinaryStringInfo(buf, + item->value.tsmatch.tsquery, + item->value.tsmatch.tsquerylen); + appendStringInfoChar(buf, '\0'); /* Safety Null Terminator */ + + /* Flatten Child 1: Expression (@) */ + if (!flattenJsonPathParseItem(buf, &chld, escontext, + item->value.tsmatch.doc, + nestingLevel, + insideArraySubscript)) + return false; + /* Patch the first slot */ + *(int32 *) (buf->data + expr_off) = chld - pos; + + /* Flatten Child 2: TSConfig (Optional) */ + if (item->value.tsmatch.tsconfig) + { + if (!flattenJsonPathParseItem(buf, &chld, escontext, + item->value.tsmatch.tsconfig, + nestingLevel, + insideArraySubscript)) + return false; + /* Patch the second slot */ + *(int32 *) (buf->data + config_off) = chld - pos; + } + else + { + /* If no config, write 0 to the slot (Null ptr) */ + *(int32 *) (buf->data + config_off) = 0; + } + } + break; case jpiFilter: argNestingLevel++; /* FALLTHROUGH */ @@ -759,6 +803,38 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, appendStringInfoChar(buf, '"'); } + if (printBracketes) + appendStringInfoChar(buf, ')'); + break; + case jpiTsMatch: + if (printBracketes) + appendStringInfoChar(buf, '('); + + jspInitByBuffer(&elem, v->base, v->content.tsmatch.doc); + printJsonPathItem(buf, &elem, false, + operationPriority(elem.type) <= + operationPriority(v->type)); + + appendStringInfoString(buf, " tsmatch "); + + escape_json_with_len(buf, + v->content.tsmatch.tsquery, + v->content.tsmatch.tsquerylen); + + if (v->content.tsmatch.tsconfig) + { + JsonPathItem config_item; + int32 config_len; + char *config_str; + + appendStringInfoString(buf, " tsconfig "); + jspInitByBuffer(&config_item, v->base, v->content.tsmatch.tsconfig); + config_str = jspGetString(&config_item, &config_len); + appendStringInfoChar(buf, '"'); + appendBinaryStringInfo(buf, config_str, config_len); + appendStringInfoChar(buf, '"'); + } + if (printBracketes) appendStringInfoChar(buf, ')'); break; @@ -914,6 +990,8 @@ jspOperationName(JsonPathItemType type) return "timestamp"; case jpiTimestampTz: return "timestamp_tz"; + case jpiTsMatch: + return "tsmatch"; default: elog(ERROR, "unrecognized jsonpath item type: %d", type); return NULL; @@ -1072,6 +1150,12 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos) read_int32(v->content.like_regex.patternlen, base, pos); v->content.like_regex.pattern = base + pos; break; + case jpiTsMatch: + read_int32(v->content.tsmatch.doc, base, pos); + read_int32(v->content.tsmatch.tsconfig, base, pos); + read_int32(v->content.tsmatch.tsquerylen, base, pos); + v->content.tsmatch.tsquery = base + pos; + break; default: elog(ERROR, "unrecognized jsonpath item type: %d", v->type); } @@ -1142,6 +1226,7 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a) v->type == jpiLast || v->type == jpiStartsWith || v->type == jpiLikeRegex || + v->type == jpiTsMatch || v->type == jpiBigint || v->type == jpiBoolean || v->type == jpiDate || @@ -1474,6 +1559,11 @@ jspIsMutableWalker(JsonPathItem *jpi, struct JsonPathMutableContext *cxt) jspInitByBuffer(&arg, jpi->base, jpi->content.like_regex.expr); jspIsMutableWalker(&arg, cxt); break; + case jpiTsMatch: + Assert(status == jpdsNonDateTime); + jspInitByBuffer(&arg, jpi->base, jpi->content.tsmatch.doc); + jspIsMutableWalker(&arg, cxt); + break; /* literals */ case jpiNull: diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index 52ae0ba4cf7..35b29148316 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -123,6 +123,12 @@ typedef struct JsonLikeRegexContext int cflags; } JsonLikeRegexContext; +typedef struct JsonTsMatchContext +{ + text *vec; + Oid tsCfg_id; +} JsonTsMatchContext; + /* Result of jsonpath predicate evaluation */ typedef enum JsonPathBool { @@ -306,6 +312,7 @@ static JsonPathExecResult executeKeyValueMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb, JsonValueList *found); static JsonPathExecResult appendBoolResult(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonValueList *found, JsonPathBool res); +static JsonPathBool executeTsMatch(JsonPathItem *jsp, JsonbValue *str, JsonbValue *rarg, void *param); static void getJsonPathItem(JsonPathExecContext *cxt, JsonPathItem *item, JsonbValue *value); static JsonbValue *GetJsonPathVar(void *cxt, char *varName, int varNameLen, @@ -800,6 +807,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, case jpiExists: case jpiStartsWith: case jpiLikeRegex: + case jpiTsMatch: { JsonPathBool st = executeBoolItem(cxt, jsp, jb, true); @@ -1868,6 +1876,16 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp, return executePredicate(cxt, jsp, &larg, NULL, jb, false, executeLikeRegex, &lrcxt); } + case jpiTsMatch: + { + JsonTsMatchContext lrcxt = {0}; + + jspInitByBuffer(&larg, jsp->base, + jsp->content.tsmatch.doc); + + return executePredicate(cxt, jsp, &larg, NULL, jb, false, + executeTsMatch, &lrcxt); + } case jpiExists: jspGetArg(jsp, &larg); @@ -1899,7 +1917,6 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp, return res == jperOk ? jpbTrue : jpbFalse; } - default: elog(ERROR, "invalid boolean jsonpath item type: %d", jsp->type); return jpbUnknown; @@ -2922,6 +2939,75 @@ executeKeyValueMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, return res; } +#include "tsearch/ts_utils.h" +#include "tsearch/ts_cache.h" +#include "utils/regproc.h" +#include "catalog/namespace.h" + +static JsonPathBool +executeTsMatch(JsonPathItem *jsp, JsonbValue *str, JsonbValue *rarg, + void *param) +{ + JsonTsMatchContext *cxt = param; + text *doc; + Datum tsquery; + Datum tsvector; + bool match; + + if (!(str = getScalar(str, jbvString))) + return jpbUnknown; + + /* Setup the Context (Run only once per predicate) */ + if (!cxt->vec) + { + /* Cache the tsquery */ + cxt->vec = cstring_to_text_with_len(jsp->content.tsmatch.tsquery, + jsp->content.tsmatch.tsquerylen); + + /* Resolve the tsconfig OID from the offset */ + if (jsp->content.tsmatch.tsconfig != 0) + { + JsonPathItem config_item; + int32 config_len; + char *config_str; + + jspInitByBuffer(&config_item, jsp->base, jsp->content.tsmatch.tsconfig); + config_str = jspGetString(&config_item, &config_len);; + + cxt->tsCfg_id = get_ts_config_oid(stringToQualifiedNameList(config_str, NULL), true); + } + else + { + cxt->tsCfg_id = getTSCurrentConfig(true); + } + } + + /* + * elog(NOTICE, "ts_config=[%s] cfgId=[%u] vector=[%.*s] query=[%s]", + * config_name, cxt->cfgId, str->val.string.len, str->val.string.val, + * jsp->content.tsmatch.query); + */ + + + doc = cstring_to_text_with_len(str->val.string.val, + str->val.string.len); + + tsvector = DirectFunctionCall2(to_tsvector_byid, + ObjectIdGetDatum(cxt->tsCfg_id), + PointerGetDatum(doc)); + + tsquery = DirectFunctionCall2(plainto_tsquery_byid, + ObjectIdGetDatum(cxt->tsCfg_id), + PointerGetDatum(cxt->vec)); + + + match = DatumGetBool(DirectFunctionCall2(ts_match_vq, + tsvector, + tsquery)); + + return match ? jpbTrue : jpbFalse; +} + /* * Convert boolean execution status 'res' to a boolean JSON item and execute diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y index 4543626ffc8..894007ad992 100644 --- a/src/backend/utils/adt/jsonpath_gram.y +++ b/src/backend/utils/adt/jsonpath_gram.y @@ -43,6 +43,11 @@ static bool makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *flags, JsonPathParseItem ** result, struct Node *escontext); +static bool makeItemTsMatch(JsonPathParseItem *doc, + JsonPathString *tsquery, + JsonPathString *tsconfig, + JsonPathParseItem ** result, + struct Node *escontext); /* * Bison doesn't allocate anything that needs to live across parser calls, @@ -81,7 +86,7 @@ static bool makeItemLikeRegex(JsonPathParseItem *expr, %token IDENT_P STRING_P NUMERIC_P INT_P VARIABLE_P %token OR_P AND_P NOT_P %token LESS_P LESSEQUAL_P EQUAL_P NOTEQUAL_P GREATEREQUAL_P GREATER_P -%token ANY_P STRICT_P LAX_P LAST_P STARTS_P WITH_P LIKE_REGEX_P FLAG_P +%token ANY_P STRICT_P LAX_P LAST_P STARTS_P WITH_P LIKE_REGEX_P FLAG_P TSMATCH_P TSCONFIG_P %token ABS_P SIZE_P TYPE_P FLOOR_P DOUBLE_P CEILING_P KEYVALUE_P %token DATETIME_P %token BIGINT_P BOOLEAN_P DATE_P DECIMAL_P INTEGER_P NUMBER_P @@ -187,6 +192,20 @@ predicate: YYABORT; $$ = jppitem; } + | expr TSMATCH_P STRING_P + { + JsonPathParseItem *jppitem; + if (! makeItemTsMatch($1, &$3, NULL, &jppitem, escontext)) + YYABORT; + $$ = jppitem; + } + | expr TSMATCH_P STRING_P TSCONFIG_P STRING_P + { + JsonPathParseItem *jppitem; + if (! makeItemTsMatch($1, &$3, &$5, &jppitem, escontext)) + YYABORT; + $$ = jppitem; + } ; starts_with_initial: @@ -357,6 +376,8 @@ key_name: | TIME_TZ_P | TIMESTAMP_P | TIMESTAMP_TZ_P + | TSCONFIG_P + | TSMATCH_P ; method: @@ -683,3 +704,46 @@ jspConvertRegexFlags(uint32 xflags, int *result, struct Node *escontext) return true; } + + +static bool +makeItemTsMatch(JsonPathParseItem *doc, + JsonPathString *tsquery, + JsonPathString *tsconfig, + JsonPathParseItem **result, + struct Node *escontext) +{ + /* Allocate the parent node */ + JsonPathParseItem *v = makeItemType(jpiTsMatch); + + /* Attach the child expression (@) */ + v->value.tsmatch.doc = doc; + + /* Attach the Pattern (Stored as raw char* because it's always a leaf) */ + v->value.tsmatch.tsquery = tsquery->val; + v->value.tsmatch.tsquerylen = tsquery->len; + + /* Handle the Configuration (Stored as a Node) */ + if (tsconfig) + { + /* + * The flattener expects tsconfig to be a JsonPathParseItem*. + * So we wrap the raw string in a jpiString node. + */ + JsonPathParseItem *conf = makeItemType(jpiString); + + conf->value.string.val = tsconfig->val; + conf->value.string.len = tsconfig->len; + + /* Assign the pointer */ + v->value.tsmatch.tsconfig = conf; + } + else + { + v->value.tsmatch.tsconfig = NULL; + } + + /* Success */ + *result = v; + return true; +} diff --git a/src/backend/utils/adt/jsonpath_scan.l b/src/backend/utils/adt/jsonpath_scan.l index 38c5841e879..86a9c03436c 100644 --- a/src/backend/utils/adt/jsonpath_scan.l +++ b/src/backend/utils/adt/jsonpath_scan.l @@ -427,9 +427,11 @@ static const JsonPathKeyword keywords[] = { {7, false, DECIMAL_P, "decimal"}, {7, false, INTEGER_P, "integer"}, {7, false, TIME_TZ_P, "time_tz"}, + {7, false, TSMATCH_P, "tsmatch"}, {7, false, UNKNOWN_P, "unknown"}, {8, false, DATETIME_P, "datetime"}, {8, false, KEYVALUE_P, "keyvalue"}, + {8, false, TSCONFIG_P, "tsconfig"}, {9, false, TIMESTAMP_P, "timestamp"}, {10, false, LIKE_REGEX_P, "like_regex"}, {12, false, TIMESTAMP_TZ_P, "timestamp_tz"}, diff --git a/src/include/utils/jsonpath.h b/src/include/utils/jsonpath.h index 6f529d74dcd..12899e0c496 100644 --- a/src/include/utils/jsonpath.h +++ b/src/include/utils/jsonpath.h @@ -104,6 +104,7 @@ typedef enum JsonPathItemType jpiLast, /* LAST array subscript */ jpiStartsWith, /* STARTS WITH predicate */ jpiLikeRegex, /* LIKE_REGEX predicate */ + jpiTsMatch, /* TSMATCH predicate */ jpiBigint, /* .bigint() item method */ jpiBoolean, /* .boolean() item method */ jpiDate, /* .date() item method */ @@ -188,6 +189,13 @@ typedef struct JsonPathItem int32 patternlen; uint32 flags; } like_regex; + struct + { + int32 doc; + char *tsquery; + uint32 tsquerylen; + int32 tsconfig; + } tsmatch; } content; } JsonPathItem; @@ -266,6 +274,13 @@ struct JsonPathParseItem uint32 len; char *val; /* could not be not null-terminated */ } string; + struct + { + JsonPathParseItem *doc; + char *tsquery; + uint32 tsquerylen; + JsonPathParseItem *tsconfig; + } tsmatch; } value; }; diff --git a/src/test/regress/expected/jsonb_jsonpath.out b/src/test/regress/expected/jsonb_jsonpath.out index 4bcd4e91a29..edc812b9a32 100644 --- a/src/test/regress/expected/jsonb_jsonpath.out +++ b/src/test/regress/expected/jsonb_jsonpath.out @@ -4510,3 +4510,49 @@ ORDER BY s1.num, s2.num; {"s": "B"} | {"s": "B"} | false | true | true | true | false (144 rows) +select jsonb_path_query('[null, 1, "running", "runs", "ran", "run", "runner", "jogging"]', 'lax $[*] ? (@ tsmatch "fly" tsconfig "english")'); + jsonb_path_query +------------------ +(0 rows) + +select jsonb_path_query('[null, 1, "running", "runs", "ran", "run", "runner", "jogging"]', 'lax $[*] ? (@ tsmatch "run" tsconfig "english")'); + jsonb_path_query +------------------ + "running" + "runs" + "run" +(3 rows) + +select jsonb_path_query('[null, 1, "running", "runs", "ran", "run", "runner", "jogging"]', 'lax $[*] ? (@ tsmatch "run" tsconfig "simple")'); + jsonb_path_query +------------------ + "run" +(1 row) + +select jsonb_path_query('[null, 1, "PostgreSQL", "postgres", "POSTGRES", "database"]', 'lax $[*] ? (@ tsmatch "Postgres" tsconfig "english")'); + jsonb_path_query +------------------ + "postgres" + "POSTGRES" +(2 rows) + +select jsonb_path_query('[null, 1, "PostgreSQL", "postgres", "POSTGRES", "database"]', 'lax $[*] ? (@ tsmatch "Postgres" tsconfig "simple")'); + jsonb_path_query +------------------ + "postgres" + "POSTGRES" +(2 rows) + +select jsonb_path_query('["fast car", "super fast car", "fast and furious", "slow car"]', 'lax $[*] ? (@ tsmatch "fast car" tsconfig "english")'); + jsonb_path_query +------------------ + "fast car" + "super fast car" +(2 rows) + +select jsonb_path_query('["fat cat", "cat fat", "fat rats"]', 'lax $[*] ? (@ tsmatch "fat & rat" tsconfig "english")'); + jsonb_path_query +------------------ + "fat rats" +(1 row) + diff --git a/src/test/regress/expected/jsonpath.out b/src/test/regress/expected/jsonpath.out index fd9bd755f52..84a11a3ebeb 100644 --- a/src/test/regress/expected/jsonpath.out +++ b/src/test/regress/expected/jsonpath.out @@ -1294,3 +1294,45 @@ FROM unnest(ARRAY['$ ? (@ like_regex "pattern" flag "smixq")'::text, 1a | f | 42601 | trailing junk after numeric literal at or near "1a" of jsonpath input | | (5 rows) +-- tsmatch (Full Text Search) +-- basic success +select '$ ? (@ tsmatch "simple")'::jsonpath; + jsonpath +------------------------ + $?(@ tsmatch "simple") +(1 row) + +select '$ ? (@ tsmatch "running" tsconfig "english")'::jsonpath; + jsonpath +-------------------------------------------- + $?(@ tsmatch "running" tsconfig "english") +(1 row) + +select '$ ? (@ tsmatch "fast & furious" tsconfig "simple")'::jsonpath; + jsonpath +-------------------------------------------------- + $?(@ tsmatch "fast & furious" tsconfig "simple") +(1 row) + +select '$[*] ? (@.title tsmatch "god" && @.rating > 5)'::jsonpath; + jsonpath +-------------------------------------------------- + $[*]?(@."title" tsmatch "god" && @."rating" > 5) +(1 row) + +select '$ ? (@ tsmatch $pattern)'::jsonpath; +ERROR: syntax error at or near "$pattern" of jsonpath input +LINE 1: select '$ ? (@ tsmatch $pattern)'::jsonpath; + ^ +-- only string literals (no variables) are allowed for tsquery +select '$ ? (@ tsmatch $var tsconfig "english")'::jsonpath; +ERROR: syntax error at or near "$var" of jsonpath input +LINE 1: select '$ ? (@ tsmatch $var tsconfig "english")'::jsonpath; + ^ +-- if a tsconfig doesn't exist it should parse nonetheless (executor will fail it) +select '$ ? (@ tsmatch "running" tsconfig "wrongconfig")'::jsonpath; + jsonpath +------------------------------------------------ + $?(@ tsmatch "running" tsconfig "wrongconfig") +(1 row) + diff --git a/src/test/regress/sql/jsonb_jsonpath.sql b/src/test/regress/sql/jsonb_jsonpath.sql index 3e8929a5269..f9ae5889ee2 100644 --- a/src/test/regress/sql/jsonb_jsonpath.sql +++ b/src/test/regress/sql/jsonb_jsonpath.sql @@ -1147,3 +1147,11 @@ SELECT jsonb_path_query_first(s1.j, '$.s > $s', vars => s2.j) gt FROM str s1, str s2 ORDER BY s1.num, s2.num; + +select jsonb_path_query('[null, 1, "running", "runs", "ran", "run", "runner", "jogging"]', 'lax $[*] ? (@ tsmatch "fly" tsconfig "english")'); +select jsonb_path_query('[null, 1, "running", "runs", "ran", "run", "runner", "jogging"]', 'lax $[*] ? (@ tsmatch "run" tsconfig "english")'); +select jsonb_path_query('[null, 1, "running", "runs", "ran", "run", "runner", "jogging"]', 'lax $[*] ? (@ tsmatch "run" tsconfig "simple")'); +select jsonb_path_query('[null, 1, "PostgreSQL", "postgres", "POSTGRES", "database"]', 'lax $[*] ? (@ tsmatch "Postgres" tsconfig "english")'); +select jsonb_path_query('[null, 1, "PostgreSQL", "postgres", "POSTGRES", "database"]', 'lax $[*] ? (@ tsmatch "Postgres" tsconfig "simple")'); +select jsonb_path_query('["fast car", "super fast car", "fast and furious", "slow car"]', 'lax $[*] ? (@ tsmatch "fast car" tsconfig "english")'); +select jsonb_path_query('["fat cat", "cat fat", "fat rats"]', 'lax $[*] ? (@ tsmatch "fat & rat" tsconfig "english")'); diff --git a/src/test/regress/sql/jsonpath.sql b/src/test/regress/sql/jsonpath.sql index 61a5270d4e8..edb515204ba 100644 --- a/src/test/regress/sql/jsonpath.sql +++ b/src/test/regress/sql/jsonpath.sql @@ -265,3 +265,17 @@ FROM unnest(ARRAY['$ ? (@ like_regex "pattern" flag "smixq")'::text, '00', '1a']) str, LATERAL pg_input_error_info(str, 'jsonpath') as errinfo; + +-- tsmatch (Full Text Search) + +-- basic success +select '$ ? (@ tsmatch "simple")'::jsonpath; +select '$ ? (@ tsmatch "running" tsconfig "english")'::jsonpath; +select '$ ? (@ tsmatch "fast & furious" tsconfig "simple")'::jsonpath; +select '$[*] ? (@.title tsmatch "god" && @.rating > 5)'::jsonpath; +select '$ ? (@ tsmatch $pattern)'::jsonpath; + +-- only string literals (no variables) are allowed for tsquery +select '$ ? (@ tsmatch $var tsconfig "english")'::jsonpath; +-- if a tsconfig doesn't exist it should parse nonetheless (executor will fail it) +select '$ ? (@ tsmatch "running" tsconfig "wrongconfig")'::jsonpath; -- 2.52.0