Re: BUG #9519: Allows storing scalar json, but fails when querying

Поиск
Список
Период
Сортировка
От Alf Kristian Støyle
Тема Re: BUG #9519: Allows storing scalar json, but fails when querying
Дата
Msg-id CA+tXr--Z7ap5mcaBVNKOi9NXd2MaZG9FO4t7cVj3cCMZjz+g6g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: BUG #9519: Allows storing scalar json, but fails when querying  (Marko Tiikkaja <marko@joh.to>)
Ответы Re: BUG #9519: Allows storing scalar json, but fails when querying  (John R Pierce <pierce@hogranch.com>)
Re: BUG #9519: Allows storing scalar json, but fails when querying  (David Johnston <polobo@yahoo.com>)
Список pgsql-bugs
If the JSON datatype accepts JSON values (not just objects), which I supposed is a valid approach, then shouldn't the JSON query operators be able to deal with that?

This is the "unfortunate" part:
select data->>'foo' from jtest;
=> ERROR:  cannot extract element from a scalar

So either, only accept JSON object (not simple JSON values), or make the JSON query operators work with JSON values as well.

Having to add an extra check constraint here is not obvious, imho.

For the record, we are working around this problem, through a small hack. Some other system is storing this kind of data in our database. We have reported a bug with them to fix it.

This is not a big problem for us, but we love Postgres, so we thought we should report this.

Cheers,
Alf



On 10 March 2014 20:52, Marko Tiikkaja <marko@joh.to> wrote:
On 3/10/14, 4:09 PM, alf.kristian@gmail.com wrote:
I think the insert should fail, since '1' is not valid JSON.

It's a valid "JSON value", it's just not an object.  If you only want to store JSON objects in the table, consider using a CHECK constraint.


Regards,
Marko Tiikkaja

В списке pgsql-bugs по дате отправления:

Предыдущее
От: John R Pierce
Дата:
Сообщение: Re: BUG #9519: Allows storing scalar json, but fails when querying
Следующее
От: John R Pierce
Дата:
Сообщение: Re: BUG #9519: Allows storing scalar json, but fails when querying