Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uqSHa-006Lzz-Q6 for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 08:10:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uqSHa-007Kkd-8W for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 08:10:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uqSHZ-007Kgv-RI for pgsql-hackers@lists.postgresql.org; Mon, 25 Aug 2025 08:10:26 +0000 Received: from mail-ua1-x933.google.com ([2607:f8b0:4864:20::933]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uqSHY-001cuL-07 for pgsql-hackers@postgresql.org; Mon, 25 Aug 2025 08:10:25 +0000 Received: by mail-ua1-x933.google.com with SMTP id a1e0cc1a2514c-8902ee514deso2900848241.1 for ; Mon, 25 Aug 2025 01:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756109424; x=1756714224; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7y9sBAbJ9wSc1VudOwmTjHxjU4L/kuXFPRYgTFM78y4=; b=iRo+Z9Pg0tcM33kprmNdSylp/4TQQiAa4AYEPXqguTTxyJyEuH/U2L2kQyYcXcJ4fU C0hwFRb1AgeAwbgeSknJs3NldhzGU6Q5RSJYGq0z79V3y8PUvdjERxRmbwYmdt0VchML JWUHcmYEoswgEvXssWY+ijnBnl3JoPR+6gFCRfR4xXZjgCeJTbPzh1W7X/39Ga5R45ZX p2EgA3/EaJoJZbxuKAvPzvsk6yqcXV8PN158WlZeNsNwWVn5jIWSGNdjHDsBfzqw8BW7 EMRr7MZ3GgWSySYxSj/buZbsORieRzJrnDpPMA9mvwi1yaWopFXKg+S2e3cjfl5jiB2k 1zJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756109424; x=1756714224; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7y9sBAbJ9wSc1VudOwmTjHxjU4L/kuXFPRYgTFM78y4=; b=IMqPzJjh8DcwXQlPCsKwSGNQGqc5rm4+fLCKRN0msp2fAy55ayI7I0R7yt1NUDtfhC htOTbCuskKg3rc0/AowswotpVlpLR1Tw4/cXvew0Gq75uoGAzcOqIVF0AXuOYeNWAYrJ AONAITrm1ymChWspkaYsyrBhoeKiiU0PxtxGf006ZBAf1T1vXt721AKBOT4boHWLWb8D 8iLlh+ApdCf2CImWTS9bEdeUu5EH/fcLDt+836c3Gq5+uFoOx/5NSBaqbAFXgYy/9MuZ e/WixXJPlmMjIeffNoFyFdn/djuWOD5dUaggBab+GbrpgL5BNZh/5zNJEmVcgqI76K/7 iydg== X-Forwarded-Encrypted: i=1; AJvYcCVgryJGRLynD1BlESIYyDVCaKCXvcxhR7+8JDvcr3Abt2AUr6u76eJi5cRM3JlYQxXyCCvgT478izKM7oXS@postgresql.org X-Gm-Message-State: AOJu0YwuBiZCddVJwifr/tqIUvK9pNfRB5ShUPcwZx+FHGug8qbARpxO LyoOcJjUI13FMn6BCfSnz9o128Wqiz9R0nrVcscJoDet/1tD+W6wNDout7OiH5ARm/14uqm4iG4 pA8Qg4CgsnBZS2Hg3yYA9/1yapUbwy/c= X-Gm-Gg: ASbGncsT24+XOQhyFUuzHrOFz153Mx3sualzKk5p50Fc87q4AT43zliJVY8FhGFl9Yr 7iFgD6ppXQ+3B4frFgGA8giHNNSeeWF7nl3OpJ0nkdtOINFYHCedXe6b3D2OBwPx1opF5wMzF8p ZJkn3fQ8nol3ziLgFurvLXcChKpg19nRReqJgcdaioh3rLdkGdrsR+eal+Pk/ZULmRFMa54iaYR ys/RBqgwfTILjHj5BdDYmwqVpKq1/OnkShCJ0dnd40xPeyM72Q6e82/sWE+4SbeXAXN2Ts= X-Google-Smtp-Source: AGHT+IGfsCS3BRQ6Xh9XoZ0ZF/kqoTpKTX5ufRIChx+z0R8KS4qZm4OP15/TnajxXw7Htb8UErU+5m7li5qfnsK9A6U= X-Received: by 2002:a05:6102:5088:b0:4e7:b77d:7fe1 with SMTP id ada2fe7eead31-51d1168ae8fmr3303693137.0.1756109423840; Mon, 25 Aug 2025 01:10:23 -0700 (PDT) MIME-Version: 1.0 References: <21fa36b4-6d56-4556-b524-9e3955b922c8@eisentraut.org> In-Reply-To: From: jian he Date: Mon, 25 Aug 2025 16:09:47 +0800 X-Gm-Features: Ac12FXxxG3jESsIdsCQQKC47P3i8N7ahQXx86F6KcbYV7LNLRka82Dq0yn8Lw9M Message-ID: Subject: Re: SQL:2023 JSON simplified accessor support To: Alexandra Wang Cc: Nikita Malakhov , Vik Fearing , Mark Dilger , Matheus Alcantara , Peter Eisentraut , Andrew Dunstan , Nikita Glukhov , PostgreSQL Hackers , "David E. Wheeler" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Aug 23, 2025 at 3:34=E2=80=AFAM Alexandra Wang wrote: > > I don=E2=80=99t understand the question. In the case of an unsupported No= de > type (not an Indices in patch 0001 or 0002), we break out of the loop > to stop transforming the remaining subscripts. So there won=E2=80=99t be = any > =E2=80=98not contiguous=E2=80=99 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) =3D=3D indirection_length) + { + Node *ind =3D 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 =3D=3D 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 co= erce to text or int4 data type. for v13-0005-Implement-read-only-dot-notation-for-jsonb.patch + i =3D 0; + foreach(lc, sbsref->refupperindexpr) { + Expr *e =3D (Expr *) lfirst(lc); + + /* When slicing, individual subscript bounds can be omitted */ + if (!e) { + sbsrefstate->upperprovided[i] =3D false; + sbsrefstate->upperindexnull[i] =3D true; + } else { + sbsrefstate->upperprovided[i] =3D 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 =3D jpi; + path =3D 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 =E2=80=94 either way, the first indirection element could not b= e + * 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;