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.96) (envelope-from ) id 1vmvwA-000KAq-0S for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Feb 2026 15:34:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vmvv9-0008hn-2h for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Feb 2026 15:32:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vmvv9-0008hf-12 for pgsql-hackers@lists.postgresql.org; Mon, 02 Feb 2026 15:32:59 +0000 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vmvv6-00000000gre-1A65 for pgsql-hackers@lists.postgresql.org; Mon, 02 Feb 2026 15:32:58 +0000 Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-5014e1312c6so29287521cf.2 for ; Mon, 02 Feb 2026 07:32:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1770046374; x=1770651174; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=/Ih0VwTQ0E+04jw1LBxLMnlXuXvaUjmgbijp27yQHtI=; b=2CFUCiUSXzO6v/ZkWWPR47DE/y206E6J4haSE49t7KWfgAugGQYW+CYGxcEU4Lov8x 79/+8gz2UsX6KIlQvwM+HCvBhsSY7A2S65mSleBXPPX+FC3gySQOG7aUSQBBUy8ncTNg 7gIYk0298EvhExOuoaJ0j26CBD3b5FMFcjvk4wmcPd6GltBExf6BfXRs1YIb7wYQnD8a IGsfflHlHkLjpXK6PiubAsm33X8yev9HseU7TyAtPn/FdBIDHTE1jFC+R8p7/Co0eLso +YyPxIxYkp14if2soIfxFQ1ydqVKdud6+NX2IM22tCR9NTYmaHuFasrGwKODJaFcBbil hMPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770046374; x=1770651174; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/Ih0VwTQ0E+04jw1LBxLMnlXuXvaUjmgbijp27yQHtI=; b=Kb25RxnJIfiRDbENu+144OJesSVHqL3m6vn0zY00ishzlSjjDV1wmm8XBg1TbOGb+/ +NMwA5Eeg0RPYzxEVjYI1lw2AYyHwPAmFUzBd4tpAgFZxkccIWTZUb13ZfE1CSzTgN9F rtKURYzB/LCC+HZ+TgK3pqEzZ08RGlZ1htYQe4cf2bP09hyF3VpJFV4V+mDtcXM6tH8J 1k2D7Y2oJKBLlz23tIMamIFhLIZwUFSbEYEwpFj6sg4PDpEh3XDJ8wtsiAqO7/+HDNyG 4W1B4EDfvKpOR95tZaFOwLWIFXsFz1Ih+9xKWU7tr3bdp/NSY0iIOib2QEBKS5TzVzFy KKgA== X-Forwarded-Encrypted: i=1; AJvYcCVgtpZYLyGDDCj7CNhQSJ+JN9xPNPUUkoIexRd8xJ+IC7HGKbE4EKkVTfCosLKykwzYaeaHZh8WcOoQdUqO@lists.postgresql.org X-Gm-Message-State: AOJu0Yz8Z8G6rqrUQH1FJgYKvC0kRY7pH0kkrlCD4mpxKMoH1MxNXQHJ /UkaGRoctngmsEHhOcRvy6I7v7jQthxOM4CrqTlLbb/Knf+TGp62u4Ox2V9VGk3D1HI= X-Gm-Gg: AZuq6aLqE+PZFbChqY2vRCb/1nr7tyCqPu67Bg0sgnSNxmW8JlXQlgea7nPdzaBRBYK 5kLBZjU2qGv6Q4TS+GiG2jNVEA85eCbpVSOsx8fxsAcvg8RYvomn1Yykhttuc0WInNiXsCjB2J0 GEW8gk77dQ3VZVRSKoSGdcWI8ewC0OeUR2qJ3ODkikhG2nwANkbmKK6qolMaCy+lPLot2Vjv6U0 wSgBIdnmB4Fem4PNJKoxU7F3yI1v87/9mpqdYsP1pb0W/yz6KElmote9TklmLq+IRqX6G5Hs3D5 r7PqLhq9SEtHMAYJlDaCAeLW4bkcCNXWDzLB1J/EGix4oi5bz9tHotKmu6VVITnvh+h5+qS37xu pNSreEaHklZ2SKOXcbFj5HONsOhyEkbAuzpRRe/97wH0vPGZzKFpyvXVQsBZMFhprqTzaTaRzRS vML5tHXyGKklldBlL/rA== X-Received: by 2002:a05:622a:1392:b0:501:50a6:962d with SMTP id d75a77b69052e-505d22c9ddbmr149316521cf.77.1770046374392; Mon, 02 Feb 2026 07:32:54 -0800 (PST) Received: from ?IPV6:2605:a601:a6b0:500::1cb? ([2605:a601:a6b0:500::1cb]) by smtp.googlemail.com with ESMTPSA id d75a77b69052e-50337bbbf8csm109389301cf.28.2026.02.02.07.32.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Feb 2026 07:32:53 -0800 (PST) Message-ID: <2cc680c1-12a9-4152-ad31-a1385a9d6912@dunslane.net> Date: Mon, 2 Feb 2026 10:32:52 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: jsonb subscripting vs SQL/JSON array accessor semantics (SQL:2023) To: Alexandra Wang , PostgreSQL Hackers Cc: Peter Eisentraut References: From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSb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JwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaYL++LAEOqrlvm2Tvq QqZRtnEAEQEAAcLAfAQYAQgAJgIbDBYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNI2BQkd EODdAAoJEJn6f8tZ/DuBfw0IAKTsfD40teP/pp+bsLLMSxPXUYrrprTj7WFB5v61p6dkpSr/ qXmMlyahdxQFaPmfVgVirB1Vk/kHiWNnnGjfUV9nB2Zg9LI0Xb9/ts3LsUiRWXzG3tkMY6XL vsVOxW4XFRND9l2q+WW93aZ1DZl+fqWfYgMvsusFRhmGFOKTRfKPta2Pkv+AhA24N4+PrR5p bU4k2MO8PAGiK8eaYKGFG1bHKuAvoDoF7WXJ3FHxuWqLnKEt4dfOLm5pAe3zq1Lt6q8azT9i QWGpSAK5vQUWQHBHpiDjdPeqKZ6HiAXIIKfSmb+jrvXBqoP+D6/K7rUjG2aXiRtTIAXms9sm VRu7cmw= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-01-16 Fr 4:26 PM, Alexandra Wang wrote: [ ... ] > ## Summary > > In all cases above, json_query() follows the SQL/JSON standard > specification. jsonb subscripting, which predates the standard, > differs in several ways: > > 1. Array access on non-arrays (scalars or objects) does not use 'lax' > mode wrapping. As a result, "[0]" does not return the original value. > 2. Non-integer subscripts are not supported. > 3. Negative subscripts use a PostgreSQL-specific extension. > > These are all edge cases and likely low-impact in practice. However, > if we were to add broader support for SQL/JSON simplified accessors > (dot notation, wildcards, item methods, etc.), which can be chained > together and include array access using the existing bracket syntax, > it seems useful to clarify what semantics we would want for array > access in those situations. > > For example, with expressions such as > >     select (jb)[0].a >     select (jb).a[0].b >     select (jb).a[-1].b > > (where jb is a jsonb value), it would be potentially confusing if > their behavior differed from the equivalent json_query() calls using > the same JSON path. > > Given this, it is unclear to me whether the expectation should be to > move closer to the SQL/JSON path semantics, or to preserve the > existing jsonb subscripting behavior and document it as > PostgreSQL-specific. > > This question comes up in the context of the dot-notation work I > mentioned at the beginning, but more generally it seems like something > we may want to be explicit about before extending the syntax further. > > I would very much appreciate any thoughts or guidance on this. > > I'd be inclined to move to the standard for 1 and 2, and document that people might need to reindex after an upgrade if they have expression indexes, but keep supporting negative subscripts. Not sure how feasible that is exactly. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com