On Mon, Apr 1, 2024 at 8:00 AM jian he <jian.universal...@gmail.com> wrote: > > +-- Should fail (JSON arguments are not passed to column paths) > +SELECT * > +FROM JSON_TABLE( > + jsonb '[1,2,3]', > + '$[*] ? (@ < $x)' > + PASSING 10 AS x > + COLUMNS (y text FORMAT JSON PATH '$ ? (@ < $x)') > + ) jt; > +ERROR: could not find jsonpath variable "x" > > the error message does not correspond to the comments intention. > also "y text FORMAT JSON" should be fine?
sorry for the noise, i've figured out why. > only the second last example really using the PASSING clause. > should the following query work just fine in this context? > > create table s(js jsonb); > insert into s select '{"a":{"za":[{"z1": [11,2222]},{"z21": [22, > 234,2345]}]},"c": 3}'; > SELECT sub.* FROM s,JSON_TABLE(js, '$' passing 11 AS "b c", 1 + 2 as y > COLUMNS (xx int path '$.c ? (@ == $y)')) sub; > > > I thought the json and text data type were quite similar. > should these following two queries return the same result? > > SELECT sub.* FROM s, JSON_TABLE(js, '$' COLUMNS( > xx int path '$.c', > nested PATH '$.a.za[1]' columns (NESTED PATH '$.z21[*]' COLUMNS (a12 > jsonb path '$')) > ))sub; > > SELECT sub.* FROM s,JSON_TABLE(js, '$' COLUMNS ( > c int path '$.c', > NESTED PATH '$.a.za[1]' columns (z json path '$') > )) sub; sorry for the noise, i've figured out why. there are 12 appearances of "NESTED PATH" in sqljson_jsontable.sql. but we don't have a real example of NESTED PATH nested with NESTED PATH. so I added some real tests on it. i also added some tests about the PASSING clause. please check the attachment. /* * JsonTableInitPlan * Initialize information for evaluating a jsonpath given in * JsonTablePlan */ static void JsonTableInitPathScan(JsonTableExecContext *cxt, JsonTablePlanState *planstate, List *args, MemoryContext mcxt) { JsonTablePlan *plan = (JsonTablePlan *) planstate->plan; int i; planstate->path = DatumGetJsonPathP(plan->path->value->constvalue); planstate->args = args; planstate->mcxt = AllocSetContextCreate(mcxt, "JsonTableExecContext", ALLOCSET_DEFAULT_SIZES); /* No row pattern evaluated yet. */ planstate->currentRow = PointerGetDatum(NULL); planstate->currentRowIsNull = true; for (i = plan->colMin; i <= plan->colMax; i++) cxt->colexprplans[i] = planstate; } JsonTableInitPathScan's work is to init/assign struct JsonTablePlanState's elements. maybe we should just put JsonTableInitPathScan's work into JsonTableInitPlan and also rename JsonTableInitPlan to "JsonTableInitPlanState" or "InitJsonTablePlanState". JsonTableSiblingJoin *join = (JsonTableSiblingJoin *) plan; just rename the variable name, seems unnecessary?
v47-0001-add-more-json_table-tests.no-cfbot
Description: Binary data