Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVnAS-001Dvh-Go for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Aug 2023 06:04:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qVnAR-00B2ax-4b for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Aug 2023 06:04:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVnAQ-00B2aW-R1 for pgsql-hackers@lists.postgresql.org; Tue, 15 Aug 2023 06:04:34 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qVnAO-000D83-2r for pgsql-hackers@postgresql.org; Tue, 15 Aug 2023 06:04:33 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1c4d1274f33so1456229fac.3 for ; Mon, 14 Aug 2023 23:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692079471; x=1692684271; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=zFg7AjJeqopqVuQSA/UKW2f85xCDbmeJWec5LfgWurM=; b=qupft6NTDVq7MqGtRCLmYG+0YAIjdFTL5F+2VnCr7noubZaBV/lVJkkr9dysR/lcnJ s1hQ3yqVVCZIOGKNmPh6wi419KPbGbNj6FPziv3fKb9AMPFMmbWM8vSFYD2PO3Fxzpkt tKDfN3B7TQAKEhsd4885wSBi38XOrbfSY6AiFNhMvDfbObdWjQPgt+GKIR1vLwyCQ9ip s272KueE09ht4wCItIWQplscm2pxKMC6do6pJuR59txcb7Xm2KyrvZGbx1S0FbR3jQXr Sr9uEOQeGf7vNd4+iREIMiM+nciBs1czgOou/BENdjUvE/K3eZNBe8eux04y+YOILnI8 EvRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692079471; x=1692684271; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zFg7AjJeqopqVuQSA/UKW2f85xCDbmeJWec5LfgWurM=; b=Nj3g9jVOf3X9htT9ZBNYn2h6wy9OzdxApwATxvXOC5lcSJ0bgynDXWiwItWg7SNE2g xz8QKgDK6wMSvbcLWaZD21M7QIcnx59bpOUG4Qo5hEvBhdogmBI+33hj3PDSMgr8dwhS +QxLWNIMQJmeDmkvhNQvjaSPkopcSZ8olAQy90/xPUv06ZuEBJqWNXwMd2BJFmCIkSUN LMJGX8LrIgcD3LGdo1K+M78hawuhCLqfXCtRwtHtijVbNtFTCR0XEtDxC8p3PaA210bw gc6QPq2ZSv57bNQlVw9jM29GF1xEW/IuKY+3rWWi6cABJ1o5hdWh9cUtIWw0uPypCyam PzRA== X-Gm-Message-State: AOJu0YzORKrVE0YShUU/KzLzWHPzLfSjJTbl8lCVdi2w6qqZVIbHQ7YI wb79z26revGqPhKFqwq4rkObgxitlg4yGI3Tifk= X-Google-Smtp-Source: AGHT+IGAspJldFvXGjarjjvgVYqPwGTtXV0lJIXnHQSn1yyImRnmfz9+kDMRurR50WnBND+oZg9FuZZMPRAPnN/9q8g= X-Received: by 2002:a05:6870:168d:b0:1bc:c06b:9a80 with SMTP id j13-20020a056870168d00b001bcc06b9a80mr13071189oae.3.1692079471311; Mon, 14 Aug 2023 23:04:31 -0700 (PDT) MIME-Version: 1.0 References: <3507485.1691090027@sss.pgh.pa.us> <900892914fdc3f477b101d699efb40e0@anastigmatix.net> <903341.1692022214@sss.pgh.pa.us> In-Reply-To: From: Andy Fan Date: Tue, 15 Aug 2023 14:04:19 +0800 Message-ID: Subject: Re: Extract numeric filed in JSONB more effectively To: Pavel Stehule Cc: Tom Lane , Chapman Flack , jian he , pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000d1bfbe0602eff375" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d1bfbe0602eff375 Content-Type: text/plain; charset="UTF-8" > > > My idea of an ideal solution is the introduction of the possibility to use > "any" pseudotype as return type with possibility to set default return > type. Now, "any" is allowed only for arguments. The planner can set the > expected type when it knows it, or can use the default type. > > so for extraction of jsonb field we can use FUNCTION > jsonb_extract_field(jsonb, text) RETURNS "any" DEFAULT jsonb > Is this an existing framework or do you want to create something new? > > if we call SELECT jsonb_extract_field(..., 'x') -> then it returns jsonb, > if we use SELECT jsonb_extract_field('...', 'x')::date, then it returns date > If so, what is the difference from the current jsonb->'f' and (jsonb->'f' )::date? > > With this possibility we don't need to touch to cast functions, and we can > simply implement similar functions for other non atomic types. > What do you mean by "atomic type" here? If you want to introduce some new framework, I think we need a very clear benefit. -- Best Regards Andy Fan --000000000000d1bfbe0602eff375 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

My idea of an ideal solution is the introduction of the possibility= to use "any" pseudotype as return type with possibility to set d= efault return type. Now, "any" is allowed only for arguments. The= planner can set the expected type when it knows it, or can use the default= type.

so for extraction of jsonb field we can use= FUNCTION jsonb_extract_field(jsonb, text) RETURNS "any" DEFAULT = jsonb

Is this an existing= framework or do you want to create something new?=C2=A0

if we call SELECT jsonb_extract_field(..., 'x= ') -> then it returns jsonb, if we use SELECT jsonb_extract_field(&#= 39;...', 'x')::date, then it returns date
=

If so, what is the difference from the cur= rent=C2=A0 jsonb->'f'=C2=A0 =C2=A0and (jsonb->'f' )::= date?=C2=A0=C2=A0

Wi= th this possibility we don't need to touch to cast functions, and we ca= n simply implement similar functions for other non atomic types.
<= div>
=C2=A0
What do you mean b= y "atomic type" here?=C2=A0 =C2=A0If you want to introduce some n= ew framework,=C2=A0 I think we need a very clear benefit.=C2=A0=C2=A0
=

--
<= div dir=3D"ltr" class=3D"gmail_signature">
Best RegardsAndy Fan
--000000000000d1bfbe0602eff375--