From: | Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> |
---|---|
To: | Chapman Flack <chap(at)anastigmatix(dot)net> |
Cc: | jian he <jian(dot)universality(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Extract numeric filed in JSONB more effectively |
Date: | 2023-09-01 03:09:22 |
Message-ID: | CAKU4AWrYOYSXMmotwhqiErci7aMz--8LxfpLiSg+0+7XNJBcuA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> An incompatible issue at error message level is found during test:
> create table jb(a jsonb);
> insert into jb select '{"a": "a"}'::jsonb;
> select (a->'a')::int4 from jb;
>
> master: ERROR: cannot cast jsonb string to type *integer*
> patch: ERROR: cannot cast jsonb string to type *numeric*
>
> That's mainly because we first extract the field to numeric and
> then cast it to int4 and the error raised at the first step and it
> doesn't know the final type. One way to fix it is adding a 2nd
> argument for jsonb_finish_numeric for the real type, but
> it looks weird and more suggestions on this would be good.
>
>
v12 is attached to address the above issue, I added a new argument
named target_oid for jsonb_finish_numeric so that it can raise a
correct error message. I also fixed the issue reported by opr_sanity
in this version.
Chap, do you still think we should refactor the code for the previous
existing functions like jsonb_object_field for less code duplication
purpose? I think we should not do it because a). The code duplication
is just ~10 rows. b). If we do the refactor, we have to implement
two DirectFunctionCall1. Point b) is the key reason I am not willing
to do it. Or do I miss other important reasons?
--
Best Regards
Andy Fan
Attachment | Content-Type | Size |
---|---|---|
v12-0001-optimize-casting-jsonb-to-a-given-type.patch | application/octet-stream | 24.9 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Corey Huinker | 2023-09-01 04:02:09 | Re: SQL:2011 application time |
Previous Message | Richard Guo | 2023-09-01 03:03:43 | Re: Should we use MemSet or {0} for struct initialization? |