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 1ksuQC-0008TD-Hc for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Dec 2020 21:14:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ksuQB-0001s8-4y for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Dec 2020 21:14:47 +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 1ksuQA-0001s0-RR for pgsql-hackers@lists.postgresql.org; Fri, 25 Dec 2020 21:14:46 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1ksuQ4-0004lb-5s for pgsql-hackers@postgresql.org; Fri, 25 Dec 2020 21:14:45 +0000 Received: by mail-ed1-x52f.google.com with SMTP id p22so4772782edu.11 for ; Fri, 25 Dec 2020 13:14:39 -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:in-reply-to; bh=55B08WPNB4kik93uejz9Pk8BhqUcv5bFH+H5DEs9XKo=; b=ZX8/yYOhgAiw+/nxGKfTARYUmoLmVgKnvfJTRH62B/xxvQ0jSt6GqW528VkQKKiZKE mNoOqcqsNZf3y3lYWQKqX8bmox5bDRyeu+JbK5CWLjzjKKjflbh3UVojOpk9cRUvJjmb mLglv1NFItP7pqcLqYcFWc+VXqVNGSncij1X8UhNDoX0U6CgJM/bQkLi/fO5rkqD6YW4 XD3nASujmCX5il8ztfhD3oLTDFsJsXv0YEjHH6N1xWlcoC07fYyxAmPI3Rj+ZEiixPsw gWweQKgrog22875g1aVdnbTcmBsKTbyLMypTqy0vQDyfhje8Y74s4jw2zjJztzHet17C 6RVA== 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=55B08WPNB4kik93uejz9Pk8BhqUcv5bFH+H5DEs9XKo=; b=ZDpSg35Nfw8+OOY9W1ahTx9q+kKLTFblor0dTGvTiAl33EB72q22gcPjqGj77WgrL4 sG0nL0GrCazUsAtgucvTCgjP1g/JO4N+RRquxysZe/U+qa3DGKroYZ7+Xs28EfjrwpCq m4/4ySifsyx+0HdIc5vM+RfkJrUq+Kp2q4vdJdphIxgQqHrPILevGpTkpSh70zGu/EPl 8yHp1ybV3X/IIdyDs036uNDsSVziG0ZrQ5JALkWLTDBSFedlnP//eL+Fdvg6BDfMapQh OSDm71F+94l4jX6pr8RnsYg//bf7hsvvovW3LYyrc9jx4NW8uFxepcnSZM0smp+xGA3t 18Tg== X-Gm-Message-State: AOAM531/4ycC4Nz6ZnMpLrRHDjrDDAfTzxjs3kl+CcrS6J5L4H6hnrZj mJtSP91VvOOM44WxG9xHOlU= X-Google-Smtp-Source: ABdhPJyTnkZyao9y37IBqMtZbQgtRm4XjoPDuzofwEQ9UQxUS+IIJiUfYSb1auylaBxnj5exPm4V2Q== X-Received: by 2002:a05:6402:17a3:: with SMTP id j3mr33149523edy.333.1608930877231; Fri, 25 Dec 2020 13:14:37 -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 ng1sm14146372ejb.112.2020.12.25.13.14.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Dec 2020 13:14:36 -0800 (PST) Date: Fri, 25 Dec 2020 22:16:03 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Tom Lane Cc: Pavel Stehule , 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: <20201225211603.4z6rxyc6p6pkuxoa@localhost> References: <107232.1608230957@sss.pgh.pa.us> <20201217200033.qdyjv4iimwyglnwt@localhost> <112397.1608236975@sss.pgh.pa.us> <20201218195925.4qj6p2kxrvkdrmur@localhost> <20201222102531.2clsvuqww6etx3by@localhost> <20201222161623.o7y3fumwcf6hk7jk@localhost> <614605.1608656233@sss.pgh.pa.us> <629720.1608664882@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <629720.1608664882@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Tue, Dec 22, 2020 at 02:21:22PM -0500, Tom Lane wrote: > Pavel Stehule writes: > > But maybe we try to design some that are designed already. Is there some > > info about index specification in SQL/JSON? > > We do have precedent for this, it's the rules about resolving argument > types for overloaded functions. But the conclusion that that precedent > leads to is that we should check whether the subscript expression can > be *implicitly* coerced to either integer or text, and fail if neither > coercion or both coercions succeed. I'd be okay with that from a system > design standpoint, but it's hard to say without trying it whether it > will work out nicely from a usability standpoint. In a quick trial > it seems it might be okay: > > regression=# create function mysub(int) returns text language sql > regression-# as $$select 'int'$$; > CREATE FUNCTION > regression=# create function mysub(text) returns text language sql > as $$select 'text'$$; > CREATE FUNCTION > regression=# select mysub(42); > mysub > ------- > int > (1 row) > > regression=# select mysub('foo'); > mysub > ------- > text > (1 row) > > regression=# select mysub(42::bigint); > ERROR: function mysub(bigint) does not exist I'm not sure I completely follow and can't immediately find the relevant code for overloaded functions, so I need to do a perception check. Following this design in jsonb_subscripting_transform we try to coerce the subscription expression to both integer and text (and maybe even to jsonpath), and based on the result of which coercion has succeeded chose different logic to handle it, right? And just for me to understand. In the above example of the overloaded function, with the integer we can coerce it only to text (since original type of the expression is integer), and with the bigint it could be coerced both to integer and text, that's why failure, isn't?