Re: Extract numeric filed in JSONB more effectively
Andy Fan <zhihui.fan1213@gmail.com>
From: Andy Fan <zhihui.fan1213@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Chapman Flack <chap@anastigmatix.net>,
Pavel Stehule <pavel.stehule@gmail.com>, jian he <jian.universality@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2023-08-15T03:24:35Z
Lists: pgsql-hackers
Attachments
- v7-0001-optimize-casting-jsonb-to-a-given-type.patch (application/octet-stream) patch v7-0001
>
>
> 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
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add trailing commas to enum definitions
- 611806cd726f 17.0 cited