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 1kuheI-0006LP-Bt for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Dec 2020 20:00: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 1kuhdl-0008LU-6e for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Dec 2020 20:00:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kuhdk-0008LN-TP for pgsql-hackers@lists.postgresql.org; Wed, 30 Dec 2020 20:00:13 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kuhdi-0001KI-Il for pgsql-hackers@postgresql.org; Wed, 30 Dec 2020 20:00:11 +0000 Received: by mail-ej1-x636.google.com with SMTP id lt17so23169986ejb.3 for ; Wed, 30 Dec 2020 12:00:10 -0800 (PST) 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=ZIynwZV7rVm48M2DYrM+klC2iBWuMOBuwGwkFof588k=; b=e7WtGkI6cjYsZJgk7OVpuaGnRB2GlyFrAoIhNdSnrQ8sXxzWbGB19mJiRah6oc1vsH OgDmSGgmhIryq34NYNPP5I/3LyM6hZwrJDvUMpgC2rGHz5Ks+4O0egCFSJBG/9O3yWFD J+bAKSXOXpH7TwZN1xmnXXPqnKyClRdCcDEE4Lbk7L2G31A+sIGoGYCaI2Sqe7qa/UjF Q+QQ+Cd90BhFrapJh7/C5mREWEQfI1j8vdPMhF5xCTQmeZ+NP+4eb7ZJKyvoEe6svMeM kc33ieqCyAY39PGFj3zYMYR6ZBkqCGha2gUsRn1yojO719wl1pVtPDSgeeiWGETRNMm7 gAmA== 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=ZIynwZV7rVm48M2DYrM+klC2iBWuMOBuwGwkFof588k=; b=Ea6Lkt4FvO6ct7I2USz2sB5yPReMQUsN6Sw7WTE6whSNQr93kelc2PndEVv18APYAr QFBjWeKykLOiFkHMxzOlY0H0PB5ZQcfr9ManQV2sXd8IyQDs8T49zJKMU+5T14saZhuR SeyR4y4MU9+xEgcrVTNReoD+oKx798i7w3Be1Ws4HeKTLUqpM4yiOTtkb+fS7diXm4YA /OeSnYgwqKw0ZQ1+Svi82lEGjf5ihszE/Jx27ZpkzicrflvO2ATkupPm8DJWmb1aPxm3 VLBHJAucll8F29ifORKUwG++xAId8D2iCTlSr78wd9OdU4BcQHn4002vwOcdosnxz8i9 gPzw== X-Gm-Message-State: AOAM532aHTMzOgQTBQr5r7z/9MfPhgnOMfSbioT4q20TnJQg41tKoCOO bQylpziXcLDAmRy9xBXVYUQR1C7Ny1NfQg== X-Google-Smtp-Source: ABdhPJylBzrUgrnBtrt+H34WYwSDhFRHUR3kAS+CtLLJHvHYsFyOXrZXiZN/KbldhDejf8rO5eiIew== X-Received: by 2002:a17:906:30c4:: with SMTP id b4mr50064258ejb.456.1609358409057; Wed, 30 Dec 2020 12:00:09 -0800 (PST) Received: from localhost (dslb-094-222-016-204.094.222.pools.vodafone-ip.de. [94.222.16.204]) by smtp.gmail.com with ESMTPSA id zn5sm19577325ejb.111.2020.12.30.12.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Dec 2020 12:00:08 -0800 (PST) Date: Wed, 30 Dec 2020 21:01:37 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Pavel Stehule Cc: Tom Lane , Andres Freund , Alexander Korotkov , Justin Pryzby , David Steele , Nikita Glukhov , Alvaro Herrera , David Fetter , Thomas Munro , Oleksandr Shulgin , Robert Haas , Michael Paquier , Oleg Bartunov , Peter Eisentraut , PostgreSQL Hackers Subject: Re: [HACKERS] [PATCH] Generic type subscripting Message-ID: <20201230200137.kgezgo33guboctc4@localhost> References: <20201222161623.o7y3fumwcf6hk7jk@localhost> <614605.1608656233@sss.pgh.pa.us> <629720.1608664882@sss.pgh.pa.us> <20201225211603.4z6rxyc6p6pkuxoa@localhost> <1292981.1609007044@sss.pgh.pa.us> <20201230134512.cnthgsfbe3mc563j@localhost> <20201230134733.q5j2pcvwutnc76cs@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, Dec 30, 2020 at 07:48:57PM +0100, Pavel Stehule wrote: > st 30. 12. 2020 v 14:46 odesílatel Dmitry Dolgov <9erthalion6@gmail.com> > napsal: > > > > On Wed, Dec 30, 2020 at 02:45:12PM +0100, Dmitry Dolgov wrote: > > > > On Sat, Dec 26, 2020 at 01:24:04PM -0500, Tom Lane wrote: > > > > > > > > In a case like jsonpath['...'], the initially UNKNOWN-type literal > > could > > > > in theory be coerced to any of these types, so you'd have to resolve > > that > > > > case manually. The overloaded-function code has an internal preference > > > > that makes it choose TEXT if it has a choice of TEXT or some other > > target > > > > type for an UNKNOWN input (cf parse_func.c starting about line 1150), > > but > > > > if you ask can_coerce_type() it's going to say TRUE for all three > > cases. > > > > > > > > Roughly speaking, then, I think what you want to do is > > > > > > > > 1. If input type is UNKNOWNOID, choose result type TEXT. > > > > > > > > 2. Otherwise, apply can_coerce_type() to see if the input type can be > > > > coerced to int4, text, or jsonpath. If it succeeds for none or more > > > > than one of these, throw error. Otherwise choose the single successful > > > > type. > > > > > > > > 3. Apply coerce_type() to coerce to the chosen result type. > > > > > > > > 4. At runtime, examine exprType() of the input to figure out what to > > do. > > > > > > Thanks, that was super useful. Following this suggestion I've made > > > necessary adjustments for the patch. There is no jsonpath support, but > > > this could be easily added on top. > > > > And the forgotten patch itself. > > > > make check fails Yeah, apparently I forgot to enable asserts back after the last benchmarking discussion, and missed some of those. Will fix. > 2. The index position was ignored. > > postgres=# update foo set a['a'][10] = '20'; > UPDATE 1 > postgres=# select * from foo; > ┌─────────────┐ > │ a │ > ╞═════════════╡ > │ {"a": [20]} │ > └─────────────┘ > (1 row) I just realized I haven't included "filling the gaps" part, that's why it works as before. Can add this too. > 1. quietly ignored update > > postgres=# update foo set a['a'][10] = '20'; > UPDATE 1 > postgres=# select * from foo; > ┌────┐ > │ a │ > ╞════╡ > │ {} │ > └────┘ > (1 row) This belongs to the original jsonb_set implementation. Although if we started to change it anyway with "filling the gaps", maybe it's fine to add one more flag to tune its behaviour in this case as well. I can check how complicated that could be.