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 1uZrQN-009Gnn-3l for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 13:34:55 +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 1uZrQK-00CxSS-LO for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 13:34:53 +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 1uZrQK-00CxSK-7p for pgsql-hackers@lists.postgresql.org; Thu, 10 Jul 2025 13:34:52 +0000 Received: from mail-vk1-xa34.google.com ([2607:f8b0:4864:20::a34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uZrQJ-006a5q-0O for pgsql-hackers@postgresql.org; Thu, 10 Jul 2025 13:34:51 +0000 Received: by mail-vk1-xa34.google.com with SMTP id 71dfb90a1353d-531426c7143so414129e0c.0 for ; Thu, 10 Jul 2025 06:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752154490; x=1752759290; 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=jMk5TD+sUZREPZ7arkzZLfisP21IF0yzfV9mcQ3qwjI=; b=jA6T7s597AwvNTXS2e1VSSi3Z15rjTgV7cIhvFCwZZJeHfFPW9pjek2e+f+j6vbvc1 hwyk3jFz/Y/3UiZkRtNZQ0GvmTOkv5o55CLCNam4Rfzp+XOcpVvNbqa6WHJySxwN1cf9 jdbBRnHZLXBtasshPKJjIEWy5hpl3JxzaQ4bESmzqdEjgc3iiOuaj3BX+souxiVS9WZH g3NsZ9FODmDzWqGfo7+3Wg4Bbtfzja+6w0hPIgpobLiY5HI7Ke5H+H/vdITf5Dh/Quzh nmQVuc4zAAVnmzfQuUwoRJNfRIxVir1lrBFxaK5Bg01bF92fliafguHMKMd6+piHkpIY 3dow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752154490; x=1752759290; 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=jMk5TD+sUZREPZ7arkzZLfisP21IF0yzfV9mcQ3qwjI=; b=XaOA5k7Z6yPGd7KTObRt/J5ftKfd/PHz4B1PdaUCCkhMoYVa//llTB45tBYY+Ruut1 nNDS9iKczQ8V9YFSnpNe/Yd33Z5XM8xlrLNdTRvNJK5IY8xKycAKH9awHcawIqNDmM2+ K9jIlhfg5980qkhnRwmIhPo+NsKM8WyxRC7r/yxEbFzbGTFnDAEg6qB7gYXsDPU2Wel9 lPS0sV5z+j8LYUNZKef1YqcX4D2AV1nV2zeWp6pyyV89DdUG/peP+q1ODptlXUfNjtsN M7dScs+aBexLhrACd0a534JyPKCoQUdqFN9LNwvkmdJKAduNyp63vyRxQC2YqnO+sWyZ P2WA== X-Forwarded-Encrypted: i=1; AJvYcCXCH7GBi61nxd3r4IckFlbfKnx6Zy1fQ7MgE4NI9hcC2ecz9mMgvERIxUSpZgzXvGcQeurudSas7/em1DfY@postgresql.org X-Gm-Message-State: AOJu0YxueUxpjFXL2PNTxttAbHE6EC+qwl3tKCGADMaDCCKanWUP1INY b0g7xee4cOZAZHB8QPGdqp4GN358/Gu2LULXrteE68t+4BJr1H3mRY+rkLrgzXjdQ1xdGQJoQv5 6FYBf6rgKDvHOQBkVsGF+kqHEc5lN3c8ibNH+Jdoo4Q== X-Gm-Gg: ASbGncvezGj6FJ3315OnZMucAjSZJhVt3WrJePK5tVxYefiLZ4/jN8iNGmjsJWyhJBZ b0uoS6i0Qz5YPhjUx4MuAMDyxIF2hn733YCKMDJQ99B88u0nToaLmavtYCFlhS/2nMp7bbxeC7b IVbzVaCFasVC5psYNUQSmkF1uprrdFeBmISa9KLFRvardDIeLuoNt5Kl+Y58d4Y+8diqB4elW7o TU= X-Google-Smtp-Source: AGHT+IEwJKJIUwcRj4hUSuB4b8gW1Yd19+L6X0rvWQVJn43vDkgiZnW8wbua6TCubxWzeRr7/cszGe8lvq3zg5AlYNU= X-Received: by 2002:a05:6122:30a9:b0:530:81ac:51be with SMTP id 71dfb90a1353d-535e6cb6f9bmr1481494e0c.8.1752154490139; Thu, 10 Jul 2025 06:34:50 -0700 (PDT) MIME-Version: 1.0 References: <21fa36b4-6d56-4556-b524-9e3955b922c8@eisentraut.org> In-Reply-To: From: jian he Date: Thu, 10 Jul 2025 21:34:12 +0800 X-Gm-Features: Ac12FXzaLPmFTcF1Ao9sggLiAmoe30SbuXgkpn3DNn5Pw1osbQug_W2i3wfockw 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 Thu, Jul 10, 2025 at 4:53=E2=80=AFPM jian he wrote: > > src7=3D# select ('{"a": 1, "b": "c", "d": [1, 2, 3]}'::jsonb).d['1'::int8= ]; > WARNING: mixed usage of jsonb simplified accessor syntax and jsonb > subscripting. > LINE 1: ...t ('{"a": 1, "b": "c", "d": [1, 2, 3]}'::jsonb).d['1'::int8]..= . > ^ > HINT: use dot-notation for member access, or use non-null integer > constants subscripting for array access. > ERROR: subscript type bigint is not supported > LINE 1: ...t ('{"a": 1, "b": "c", "d": [1, 2, 3]}'::jsonb).d['1'::int8]..= . > ^ > HINT: jsonb subscript must be coercible to either integer or text. > > The above example looks very bad. location printed twice, hint message > is different. > two messages level (ERROR, WARNING). > For plainSELECT statement, we have WARNING only in src/test/regress/expected/xml.out, src/test/regress/expected/xml_2.out for example: SELECT xpath('/*', ''); WARNING: line 1: xmlns: URI relative is not absolute ^ xpath -------------------------------------- {""} (1 row) so i am not sure a plain SELECT statement issuing WARNING is appropriate. ------------------------------------------ in jsonb_subscript_make_jsonpath we have foreach(lc, *indirection) { if (IsA(accessor, String)) .... else if (IsA(accessor, A_Indices)) else /* * Unsupported node type for creating jsonpath. Instead of * throwing an ERROR, break here so that we create a jsonpath f= rom * as many indirection elements as we can and let * transformIndirection() fallback to alternative logic to hand= le * the remaining indirection elements. */ break; } the above ELSE branch comments look suspicious to me. transformIndirection->transformContainerSubscripts->jsonb_subscript_transfo= rm->jsonb_subscript_make_jsonpath As you can see, transformIndirection have a long distance from jsonb_subscript_make_jsonpath, let transformIndirection handle remaining indirection elements seems not go= od. if you look at src/backend/parser/gram.y line 16990. transformIndirection(ParseState *pstate, A_Indirection *ind) ind->indirection can be be Node of String, A_Indices, A_Star also the above ELSE branch never reached in regress tests. ------------------------------------------ typedef struct FieldAccessorExpr { Expr xpr; char *fieldname; /* name of the JSONB object field accesse= d via * dot notation */ Oid faecollid pg_node_attr(query_jumble_ignore); int location; } FieldAccessorExpr; first field as NodeTag should be just fine? I am not sure the field "location" is needed now, if it is needed, it shoul= d be type as ParseLoc. we should add it to src/tools/pgindent/typedefs.list