Re: Extract numeric filed in JSONB more effectively

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Chapman Flack <chap(at)anastigmatix(dot)net>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Extract numeric filed in JSONB more effectively
Date: 2023-08-15 03:24:35
Message-ID: CAKU4AWrGM5bK7wi4Y8bTYhKgh=A1fW=X00eC_jfk6_JXyaEURQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
>
> jsonb_extract_xx_type just cares about the argtype, but
> 'explain select xx' will still access the const->constvalue.
> const->constvalue is 0 which is set by makeNullConst currently,
> and it is ok for the current supported type.
>

The exception is numeric data type, the constvalue can't be 0.
so hack it with the below line. maybe not good enough, but I
have no better solution now.

+ Const *target =
makeNullConst(fexpr->funcresulttype,
+
-1,
+
InvalidOid);
+ /*
+ * Since all the above functions are strict, we
can't input
+ * a NULL value.
+ */
+ target->constisnull = false;
+
+ Assert(target->constbyval || target->consttype ==
NUMERICOID);
+
+ /* Mock a valid datum for !constbyval type. */
+ if (fexpr->funcresulttype == NUMERICOID)
+ target->constvalue =
DirectFunctionCall1(numeric_in, CStringGetDatum("0"));

--
Best Regards
Andy Fan

Attachment Content-Type Size
v7-0001-optimize-casting-jsonb-to-a-given-type.patch application/octet-stream 27.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-08-15 04:07:27 Re: Using defines for protocol characters
Previous Message jian he 2023-08-15 03:12:16 Re: proposal: jsonb_populate_array