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 1kublW-0003LZ-RL for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Dec 2020 13:43:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kublV-0005rc-Q6 for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Dec 2020 13:43:49 +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 1kublV-0005rV-J4 for pgsql-hackers@lists.postgresql.org; Wed, 30 Dec 2020 13:43:49 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kublQ-000480-T5 for pgsql-hackers@postgresql.org; Wed, 30 Dec 2020 13:43:49 +0000 Received: by mail-ed1-x534.google.com with SMTP id cw27so15462679edb.5 for ; Wed, 30 Dec 2020 05:43:44 -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=lDZEcbFMS5lW+fmUBhwXPZwx0MJQ8Nqlc4Zwp7e4ao0=; b=cG8l9fUZwxhKECdb6jKgTHZFP2kNUhzI+xGl9TIiG9qJE0nRyfMbd94FV4Y/UjeOWo 27hYf2CMhePe52j7yZEyVPpNrtt/PP2cNRBmIWc4L4tZqrB10xCQp/Vp9wG+18T4QUIz 0yP3dX6Q/opjPScs2M9xJm0QNSIk1YpK6qBrjQjNUGzQDM88iAWNthKoS6nnmIgwzWh3 Mxxp3steeolWm5Uka64u+OUrXszZ0rZ9sRSgbMq3HM49I8i9ugvDJH59gypBC/N+kxv6 wt45BsfQsg3ltz6VaQhOqjmY32ffeJ8TZ1uD3AIcOkeCfQjZItUTUjROpjzgkQbBeuCA SFoA== 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=lDZEcbFMS5lW+fmUBhwXPZwx0MJQ8Nqlc4Zwp7e4ao0=; b=jIBmOup1rssmOXODqihcch7x8Lq8Hqv7ZYAEpLVahDjTodORgiyl6ziYJvAQtxVUyP 9ceqJQ+CeTfqBevTRngBOpVqb3sSDEQnyeUGDQVfOuIIIDiBU3B6/qbxXPED6kXieAN2 zmpfgjAJRFreUIu4SiMs/rG/vr9yR+Vu5lXl7bFv28mkURn8YN6iJ58UgEdOULmQQ6gO APq+fMJx2BBRiXVd2GZflott94WOQcnl5E0LIO9c9AFWCOZRIHJYTn9FwEdHAGsyMUlt 1GbcQq61QuHXpghlqH9y/decY8Rr8PAIvAcCUJxE9/+TEyJqYtRfPykSdJO4zKxHU160 tFnw== X-Gm-Message-State: AOAM531SrrDwTsM8YuofId3mqcktwkCgzkroq49KnixW0jyc7Vlt2X34 5fyq3ff3XalSLP0gQ6S1+jw= X-Google-Smtp-Source: ABdhPJzyIXmqfrOUc2ilkHx+K0o0GoKW5zFQcJPTlONswKPL+wp3mfryhRlQ5y2/IV0RlXqyysU2Hw== X-Received: by 2002:a05:6402:513:: with SMTP id m19mr50665555edv.244.1609335824095; Wed, 30 Dec 2020 05:43:44 -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 t15sm14665490eds.38.2020.12.30.05.43.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Dec 2020 05:43:43 -0800 (PST) Date: Wed, 30 Dec 2020 14:45:12 +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: <20201230134512.cnthgsfbe3mc563j@localhost> References: <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> <20201225211603.4z6rxyc6p6pkuxoa@localhost> <1292981.1609007044@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1292981.1609007044@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > 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.