Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJE9O-00006C-DJ for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Sep 2020 11:01:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kJE9N-0008Ao-Ao for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Sep 2020 11:01:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kJE9N-0008Ah-14 for pgsql-hackers@lists.postgresql.org; Fri, 18 Sep 2020 11:01:57 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kJE9K-0006lk-NL for pgsql-hackers@postgresql.org; Fri, 18 Sep 2020 11:01:56 +0000 Received: by mail-wr1-x444.google.com with SMTP id z4so5173431wrr.4 for ; Fri, 18 Sep 2020 04:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6sEDcqf7+VNG0cAq2QcfGF+XMwtwch0pOeniA08jv9g=; b=NMIn0HJse8SOaQylVqY76A5/PLBBxwl2Kss7SMJ3LopPIwosY4KoqpgGoV/yv+xpPb DntEpboyyr38/XFTxqqyT7LEeYf4HHfiQnx5PFSLUoxBkyJ7VIDEJ4se4kmhvX88nH9L TngzfIgeyjHr3Fqks5nVCRrjt9ZtU2bQJNicdWH/8SGhgBaD98KBR7XWY7U+dSpzV2gr vyYN+nOHQlYb4nbDjve7z0I4ykYpIt33ArxqQ+QV0m2mnFC6OM8j/BhACM7bkkVB55Si VlXD1eJXWpuJJyZAk5OTNTm15FXqt5jOwdY/8jxasKXH7As+VYb5cale/poGj2mUB9ho ZMpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6sEDcqf7+VNG0cAq2QcfGF+XMwtwch0pOeniA08jv9g=; b=KOzcqDsdCyix7LMZqEydzwLpEkAnEJFgq0pY4Rjc6aEY5O6gq7fwJC1UwS0Or/3bPT 8H4uvucLcTlx6oSBtzX4VeeWpUEVs74W85olAo+jnJAfTvndT3TAx2oCfYHQ88Gg9tuY Kn2MZscP3X/fQFhPE+SoPzvS/1Rth/JcHPBuxzyuWzy5HS7ddU7liMGZ0GqQpeErIqRb M5sYgjJ9HEZGkMH/hltaDiizImXe2mrEXPAzwMsx8A5IdlYAyQ2hvSHlq3G22i1CdQco WX8WYXeCkMzgwVHA1FhiUQyDqxriCkcA/l7w/42wY8hKSEjIz5glFvbXfmdLHKO3D9pT o2zw== X-Gm-Message-State: AOAM532VZr1bNL6aHrIdufe9pVwoeB1yG0/VgepYjWKR5GIQbOqw/mK1 kDSwy7RD0KMJzxI000p9WiI= X-Google-Smtp-Source: ABdhPJxVEQhBR1RICgIPTnI5q+yX1OORNm6yoShoBgjQUZ+hcTom0ljHWywzHuCcydoke+zGJPXxQw== X-Received: by 2002:a5d:574a:: with SMTP id q10mr14772461wrw.127.1600426913784; Fri, 18 Sep 2020 04:01:53 -0700 (PDT) Received: from localhost (dslb-178-005-232-008.178.005.pools.vodafone-ip.de. [178.5.232.8]) by smtp.gmail.com with ESMTPSA id h8sm4634565wrw.68.2020.09.18.04.01.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Sep 2020 04:01:52 -0700 (PDT) Date: Fri, 18 Sep 2020 13:02:04 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Pavel Stehule Cc: Justin Pryzby , Tom Lane , David Steele , Nikita Glukhov , Alvaro Herrera , David Fetter , Thomas Munro , Thomas Munro , Oleksandr Shulgin , Robert Haas , Andres Freund , Michael Paquier , Oleg Bartunov , Peter Eisentraut , PostgreSQL Hackers Subject: Re: [HACKERS] [PATCH] Generic type subscripting Message-ID: <20200918110204.77yu4ioqlhhfhcya@localhost> References: <20200805140422.fzwnvq7qr5vsgx3b@localhost> <20200909210435.GU18552@telsasoft.com> <20200916093703.rkyl66ggdhmw5pc6@localhost> <20200917105849.vgqhutrooatdxwzq@localhost> <20200917135627.7koag6rnhshgjlai@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Thu, Sep 17, 2020 at 05:19:19PM +0200, Pavel Stehule wrote: > > ok, then I think we can design some workable behaviour > > My first rule - there should not be any implicit action that shifts > positions in the array. It can be explicit, but not implicit. It is true > for positive indexes, and it should be true for negative indexes too. > > then I think so some like this can work > > if (idx < 0) > { > if (abs(idx) > length of array) > exception("index is of of range"); > array[length of array - idx] := value; > } > else > { > /* known behave for positive index */ > } In this way (returning an error on a negative indices bigger than the number of elements) functionality for assigning via subscripting will be already significantly differ from the original one via jsonb_set. Which in turn could cause a new wave of something similar to "why assigning an SQL NULL as a value returns NULL instead of jsonb?". Taking into account that this is not absolutely new interface, but rather a convenient shortcut for the existing one it probably makes sense to try to find a balance between both consistency with regular array and similarity with already existing jsonb modification functions. Having said that, my impression is that this balance should be not fully shifted towards consistensy with the regular array type, as jsonb array and regular array are fundamentally different in terms of implementation. If any differences are of concern, they should be addressed at different level. At the same time I've already sort of gave up on this patch in the form I wanted to see it anyway, so anything goes if it helps bring it to the finish point. In case if there would be no more arguments from other involved sides, I can post the next version with your suggestion included.