On Sat, Aug 23, 2025 at 3:34 AM Alexandra Wang <alexandra.wang....@gmail.com> wrote: > > I don’t understand the question. In the case of an unsupported Node > type (not an Indices in patch 0001 or 0002), we break out of the loop > to stop transforming the remaining subscripts. So there won’t be any > ‘not contiguous’ indirection elements. >
Sorry, my last message is wrong. this time, I applied v13-0001 to v13-0005. and I found some minor issues..... v13-0002-Allow-Generic-Type-Subscripting-to-Accept-Dot-No.patch + /* + * Error out, if datatype failed to consume any indirection elements. + */ + if (list_length(*indirection) == indirection_length) + { + Node *ind = linitial(*indirection); + + if (noError) + return NULL; + + if (IsA(ind, String)) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("type %s does not support dot notation", + format_type_be(containerType)), + parser_errposition(pstate, exprLocation(containerBase)))); + else if (IsA(ind, A_Indices)) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("type %s does not support array subscripting", + format_type_be(containerType)), + parser_errposition(pstate, exprLocation(containerBase)))); + else + elog(ERROR, "invalid indirection operation: %d", nodeTag(ind)); + } these error message still not reached after I apply v13-0005-Implement-read-only-dot-notation-for-jsonb.patch maybe we can simply do + if (noError) + return NULL; + + ereport(ERROR, + errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("type %s does not support subscripting", + format_type_be(containerType)), + parser_errposition(pstate, exprLocation(containerBase))); ? for V13-0004. in master we have if (subExpr == NULL) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("jsonb subscript must have text type"), parser_errposition(pstate, exprLocation(subExpr)))); but this part is removed from v13-0004-Extract-coerce_jsonpath_subscript ? coerce_jsonpath_subscript_to_int4_or_text maybe we can just rename to coerce_jsonpath_subscript, then add some comments explaining why currently only support result node coerce to text or int4 data type. for v13-0005-Implement-read-only-dot-notation-for-jsonb.patch + i = 0; + foreach(lc, sbsref->refupperindexpr) { + Expr *e = (Expr *) lfirst(lc); + + /* When slicing, individual subscript bounds can be omitted */ + if (!e) { + sbsrefstate->upperprovided[i] = false; + sbsrefstate->upperindexnull[i] = true; + } else { + sbsrefstate->upperprovided[i] = true; + /* Each subscript is evaluated into appropriate array entry */ + ExecInitExprRec(e, state, + &sbsrefstate->upperindex[i], + &sbsrefstate->upperindexnull[i]); + } + i++; } curly braces should be put into the next new line. there are two + if (!sbsref->refjsonbpath) +{ +} maybe we can put these two together. +SELECT (jb)['b']['x'].z FROM test_jsonb_dot_notation; -- returns NULL with warnings + z +--- + +(1 row) there is no warning, "returns NULL with warnings" should be removed. +-- clean up +DROP TABLE test_jsonb_dot_notation; \ No newline at end of file to remove "\ No newline at end of file" you need to add a newline to jsonb.sql, you may see other regress sql test files. + foreach(lc, *indirection) + if() + { + } + else + { + /* + * Unexpected node type in indirection list. This should not + * happen with current grammar, but we handle it defensively by + * breaking out of the loop rather than crashing. In case of + * future grammar changes that might introduce new node types, + * this allows us to create a jsonpath from as many indirection + * elements as we can and let transformIndirection() fallback to + * alternative logic to handle the remaining indirection elements. + */ + Assert(false); /* not reachable */ + break; + } + + /* append path item */ + path->next = jpi; + path = jpi; + pathlen++; If the above else branch is reached, it will crash due to `Assert(false);`, which contradicts the preceding comments. to make the comments accurate, we need remove " Assert(false); /* not reachable */" ? /* - * Transform and convert the subscript expressions. Jsonb subscripting - * does not support slices, look only at the upper index. + * We would only reach here if json simplified accessor is not needed, or + * if jsonb_subscript_make_jsonpath() didn't consume any indirection + * element — either way, the first indirection element could not be + * converted into a JsonPath component. This happens when it's a non-slice + * A_Indices with a non-integer upper index. The code below falls back to + * traditional jsonb subscripting for such cases. */ the above comments, "non-integer" part is wrong? For example, the below two SELECTs both use "traditional" jsonb subscripting logic. CREATE TABLE ts1 AS SELECT '[1, [2]]' ::jsonb jb; SELECT (jb)[1] FROM ts1; SELECT (jb)['a'] FROM ts1;