Re: Extract numeric filed in JSONB more effectively
| От | Andy Fan |
|---|---|
| Тема | Re: Extract numeric filed in JSONB more effectively |
| Дата | |
| Msg-id | CAKU4AWrYOYSXMmotwhqiErci7aMz--8LxfpLiSg+0+7XNJBcuA@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Extract numeric filed in JSONB more effectively (Andy Fan <zhihui.fan1213@gmail.com>) |
| Ответы |
Re: Extract numeric filed in JSONB more effectively
|
| Список | 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 integerpatch: ERROR: cannot cast jsonb string to type numericThat's mainly because we first extract the field to numeric andthen cast it to int4 and the error raised at the first step and itdoesn't know the final type. One way to fix it is adding a 2ndargument for jsonb_finish_numeric for the real type, butit 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
Вложения
В списке pgsql-hackers по дате отправления: