> 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
v12-0001-optimize-casting-jsonb-to-a-given-type.patch
Description: Binary data
