Re: Extract numeric filed in JSONB more effectively
От | Andy Fan |
---|---|
Тема | Re: Extract numeric filed in JSONB more effectively |
Дата | |
Msg-id | CAKU4AWqQjMREZpOOECC6duV-VbEYYAdP6EL+VaK=-X7q-JQjFw@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Extract numeric filed in JSONB more effectively (jian he <jian.universality@gmail.com>) |
Ответы |
Re: Extract numeric filed in JSONB more effectively
|
Список | pgsql-hackers |
Hi Jian,
SELECT (test_json -> 'field1')::int4 FROM test_jsonb WHERE json_type
= 'object';
-ERROR: cannot cast jsonb string to type integer
+ERROR: unknown jsonb type: 1125096840
Thanks for the report! The reason is I return the address of a local variable.
{
JsonbValue *v;
JsonbValue vbuf;
v = getKeyJsonValueFromContainer(&jb->root,
VARDATA_ANY(key),\
VARSIZE_ANY_EXHDR(key),
&vbuf);
PG_RETURN_POINTER(v);
}
Here the v points to vbuf which is a local variable in stack. I'm confused
that why it works on my local machine and also works in the most queries
in cfbot, the fix is below
v = getKeyJsonValueFromContainer(&jb->root,
VARDATA_ANY(key),\
VARSIZE_ANY_EXHDR(key),
NULL);
VARSIZE_ANY_EXHDR(key),
NULL);
I will send an updated version soon.
Best Regards
Andy Fan
В списке pgsql-hackers по дате отправления: