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 1kIrcj-0007pO-Vs for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Sep 2020 10:58:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kIrci-0007Tc-Rw for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Sep 2020 10:58:44 +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 1kIrci-0007TU-HJ for pgsql-hackers@lists.postgresql.org; Thu, 17 Sep 2020 10:58:44 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kIrcf-0001oa-I0 for pgsql-hackers@postgresql.org; Thu, 17 Sep 2020 10:58:44 +0000 Received: by mail-wr1-x443.google.com with SMTP id z1so1583367wrt.3 for ; Thu, 17 Sep 2020 03:58:41 -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:content-transfer-encoding:in-reply-to; bh=X5zhaz5Pws54gdndv3fdy/rQSNx3I6hRqglgzQ9fy/Q=; b=e+ZZ8h7iuLgbei0+I9mjfxHE9cCEZ+UPOBGRQse5IcXpfF75R3UHEUJgEjr3FXKPah XSp7NqdEsQgiUSiB72JYOm0bFVKAdlT0kiZgl+y4kYlGtthVXb7Q4Q7GDFMBTGJvVIyx LGUb7xplFU1qzhGb1Mb4Ou7/Dg2sfWGIdT7Bx3bnOy29tvAVd58UTZ3n2hfBDb6482RK 2Y9YnHv2a5jopnTAdQ0To7pX/nFZ5YdgTy35c4pJGP5Z37B62ZWSQZ3kfCrIfRcIQXjZ rx8wpaqAJ60+OA9pVfLl3txUd1nPVhfXlcThuuUpbrA08Imt1oD+70vwaQQdE8hgqi1C 5bSg== 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:content-transfer-encoding :in-reply-to; bh=X5zhaz5Pws54gdndv3fdy/rQSNx3I6hRqglgzQ9fy/Q=; b=ta2EJLPqMiyhWiLccTuxf+Zc35GQcjUylpcTkn8Vvj6gBot2qR96UduWRnOT/Cw9eb 8pZaMDtdkUmRM/WAH7B9yQpNhHe6NAVh9ep0NflH+jvs4oG+tseFrgRkgZx7aCONk7EE cbuwjJGLAHxv6YIlfOcZKwENTPgFGoEXI2FC3niZ2ffvUrwGqopRw+sJsG8ohvX207// 6ofKFtaDZxzH+vDgtpsZzzWtck/FiSYsJJAYe41BM2y6Qebnukr4GqCO3PFv6B6EipWF AWJOMDqQ6KpOnbrVQdPaZzy8dO/A/yyFMtxN/bAGMhWpjDfdNo/26bYqedkVn63CwMTe rB2w== X-Gm-Message-State: AOAM5313HZA1prp9kRYfy/R1GpZuNnigP8+w/IwtnA+oKGwnubJfmQJG 1BQXYO0gVXAiW3UeeA03Xv4= X-Google-Smtp-Source: ABdhPJy6h7tOHvswa/5w/XCGPk+mfGBc+S7TQPqWyuemxfQ7ZgK7p35B9zl8bZSRWgKyOI3SpU9IUg== X-Received: by 2002:a5d:4081:: with SMTP id o1mr32548623wrp.338.1600340319418; Thu, 17 Sep 2020 03:58:39 -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 u66sm10773031wmg.44.2020.09.17.03.58.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 03:58:38 -0700 (PDT) Date: Thu, 17 Sep 2020 12:58:49 +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: <20200917105849.vgqhutrooatdxwzq@localhost> References: <20200720160216.lav6vmyv6wbg7bfl@localhost> <20200728134308.qsstgwyyx3ngsfcw@localhost> <1808585.1596224122@sss.pgh.pa.us> <20200801143334.d7d3tsb7gaezx6vq@localhost> <20200805140422.fzwnvq7qr5vsgx3b@localhost> <20200909210435.GU18552@telsasoft.com> <20200916093703.rkyl66ggdhmw5pc6@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Wed, Sep 16, 2020 at 01:52:27PM +0200, Pavel Stehule wrote: > > > On Tue, Sep 15, 2020 at 08:42:40PM +0200, Pavel Stehule wrote: > > > > > > Maybe I found a another issue. > > > > > > create table foo(a jsonb); > > > > > > postgres=# select * from foo; > > > ┌───────────────────────────────────────────────────────────────────┐ > > > │ a │ > > > ╞═══════════════════════════════════════════════════════════════════╡ > > > │ [0, null, null, null, null, null, null, null, null, null, "ahoj"] │ > > > └───────────────────────────────────────────────────────────────────┘ > > > (1 row) > > > > > > It is working like I expect > > > > > > but > > > > > > postgres=# truncate foo; > > > TRUNCATE TABLE > > > postgres=# insert into foo values('[]'); > > > INSERT 0 1 > > > postgres=# update foo set a[10] = 'ahoj'; > > > UPDATE 1 > > > postgres=# select * from foo; > > > ┌──────────┐ > > > │ a │ > > > ╞══════════╡ > > > │ ["ahoj"] │ > > > └──────────┘ > > > (1 row) > > > > Thanks for looking at the last patch, I appreciate! The situation you've > > mention is an interesting edge case. If I understand correctly, the > > first example is the result of some operations leading to filling gaps > > between 0 and "ahoj". In the second case there is no such gap that's why > > nothing was "filled in", although one could expect presence of a "start > > position" and fill with nulls everything from it to the new element, is > > that what you mean? > > > > I expect any time > > a[10] := 10; > > ? a[10] --> 10 > > === > > > postgres=# truncate foo; > TRUNCATE TABLE > postgres=# insert into foo values('[]'); > INSERT 0 1 > postgres=# update foo set a[10] = 'AHOJ'; > UPDATE 1 > postgres=# select (a)[10] from foo; > ┌───┐ > │ a │ > ╞═══╡ > │ ∅ │ > └───┘ > (1 row) > > There should be consistency > > postgres=# create table foo2(a text[]); > CREATE TABLE > postgres=# insert into foo2 values('{}'); > INSERT 0 1 > postgres=# update foo set a[10] = 'AHOJ'; > UPDATE 1 > postgres=# select (a)[10] from foo; > ┌────────┐ > │ a │ > ╞════════╡ > │ "AHOJ" │ > └────────┘ > (1 row) > > and some natural behaviour - any special case with different behaviour is a > bad thing generally. Yeah, I see your point. IIRC there is no notion of an arbitrary index in jsonb array, so it needs to be done within an assignment operation similar to how the last patch fills the gaps between elements. Taking into account, that if there are more than one elements in the array, all the gaps should be filled and the behaviour is already the same as you described, what needs to be changed is more nulls need to be added around before the first element depending on the assignment index. I have my concerns about the performance side of this implementation as well as how surprising this would be for users, but at the same time the patch already does something similar and the code change should not be that big, so why not - I can include this change into the next rebased version. But it still can cause some confusion as it's not going to work for negative indices, so update foo set a[-10] = 1; and select a[-10] from foo; can return different value from what was assigned. Otherwise, if we will try to fix a[-10] assignment in the same way, it will prepend the array and a[10] will not return the same value.