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 1qWJRc-002qVx-BJ for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Aug 2023 16:32:28 +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 1qWJRZ-007zP8-Bh for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Aug 2023 16:32:25 +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 1qWJRZ-007zOe-1W for pgsql-hackers@lists.postgresql.org; Wed, 16 Aug 2023 16:32:25 +0000 Received: from mail-vs1-xe34.google.com ([2607:f8b0:4864:20::e34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qWJRU-000TPK-V9 for pgsql-hackers@postgresql.org; Wed, 16 Aug 2023 16:32:23 +0000 Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-4477b141804so2843436137.3 for ; Wed, 16 Aug 2023 09:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692203540; x=1692808340; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SJe0Aw9cbWfTzDSapI2dPKK2k4wOR+bUK4mgWveI/Ns=; b=YnZZe7Wg/4xcKKDyh7dRuqPCfCVnkqAdUJRIO4oBZNk0vx+sSQCjQ0QdbEFJy1xWVj OVlOk+ahmcieVp/Lrcrlh50/QcMz9SoTrIGpjQkZQwsobbtHpXySLUvQ5hLZj7LpcJVE SK4LoH1xJ1uG/WYEPhuhOZm6cHsBTZre4cLmX/ddgMP9w0LZNbVl7iissqDLzXnw2JLc VTjlCO14wJXDnrkfnSdtKpbsCc+qa6rJrzE1OR/u2Pn/ufZNrCuRAdnwZ56CNUG1uw5F /uS99BsGbNAhSgoXwfmtHUnz4GNe0HiM0p9/fkL+nz3LLEjIs2vLQbiDS9opbS9MrI18 YnVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692203540; x=1692808340; h=content-transfer-encoding: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=SJe0Aw9cbWfTzDSapI2dPKK2k4wOR+bUK4mgWveI/Ns=; b=k4YCwQOzmcVMtpwvhvyQ0tnVyZqeUrGhEfr89T8QtwHYaw+LgxZDpbRPnNotIeId0R 6ipuWyij0pxTDYWiqh6SxXtFGqUZdFjjNiD2a9M3inCp26g5xhIFgMgCyNpJMIsJyMtb aQo4kHy6/AsrLnun+gah48hBd/Czd5lw0NVjg6LFVFIKauTRYhjAVoEx6uUeS1hFiV9x JOEV99ZyffwPu/t+eGC1ltQjqzUJphwA8n/8nr9CJ3HWAV5nLBjs+vMksDg0uUyoAoU2 IHPIQQLisHzrS6Uv52ZwX8kNSZXxaHA1TPt9LP9RLE5JSk2jvvNXj7sTOszWH7nXteuF zvHQ== X-Gm-Message-State: AOJu0YxfFYvLFUIhTMB8VwwqC3jba2dyhT9s0SQeVSqz63x5ef0/xEK1 kQUhjopcWiHWf6w4tfW0tchbSrqoLk/VeQXrNGZhuC1SHMzI+Q== X-Google-Smtp-Source: AGHT+IHKAFD8b3k99UUhbvA+2kZeFI8Ur0oLT+JLHD4eUbUOiAFaYq8tJr09xA/tzgh7mgwf0F7UnUv+W6D280BjJIA= X-Received: by 2002:a67:ba0e:0:b0:443:6397:2505 with SMTP id l14-20020a67ba0e000000b0044363972505mr2310051vsn.19.1692203539993; Wed, 16 Aug 2023 09:32:19 -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: jian he Date: Thu, 17 Aug 2023 00:32:08 +0800 Message-ID: Subject: Re: Extract numeric filed in JSONB more effectively To: Andy Fan Cc: Pavel Stehule , Tom Lane , Chapman Flack , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Aug 16, 2023 at 2:28=E2=80=AFPM Andy Fan = wrote: > > update with the correct patch.. regression=3D# select proname, pg_catalog.pg_get_function_arguments(oid) from pg_proc where proname =3D 'jsonb_extract_path_type'; proname | pg_get_function_arguments -------------------------+-------------------------------------------------= ------------------- jsonb_extract_path_type | from_json jsonb, VARIADIC path_elems text[], target_oid anyelement (1 row) VARIADIC should be the last argument? select jsonb_array_element_type(jsonb'[1231]',0, null::int); now return null. Should it return 1231? regression=3D# select jsonb_array_element_type(jsonb'1231',0, 1::int); jsonb_array_element_type -------------------------- 1231 (1 row) not sure if it's ok. if you think it's not ok then: + if (!JB_ROOT_IS_ARRAY(jb)) +PG_RETURN_NULL(); change to +if (JB_ROOT_IS_SCALAR(jb) || !JB_ROOT_IS_ARRAY(jb)) +PG_RETURN_NULL(); select jsonb_array_element_type(jsonb'[1231]',0, '1'::jsonb); will crash, because jsonb_array_element_type call cast_jsonbvalue_to_type then in switch case, it will go to default part. in default part you have Assert(false); also in cast_jsonbvalue_to_type, PG_RETURN_POINTER(NULL) code won't be reac= hed. in jsonb_cast_support function. you already have !jsonb_cast_is_optimized(fexpr->funcresulttype)). then in the default branch of cast_jsonbvalue_to_type, you can just elog(error, "can only cast to xxx type"). jsonb_array_element_type, jsonb_object_field_type, third argument is anyelement. so targetOid can be any datatype's oid.