Re: potential bug in JSON

Поиск
Список
Период
Сортировка
От Andrew Dunstan
Тема Re: potential bug in JSON
Дата
Msg-id 51A4D299.7060501@dunslane.net
обсуждение исходный текст
Ответ на potential bug in JSON  (Szymon Guz <mabewlun@gmail.com>)
Список pgsql-hackers
On 05/28/2013 11:38 AM, Szymon Guz wrote:
> I've found a potential bug. Why the "->" operator returns JSON instead 
> of TEXT? It doesn't make sens for me, and the documentation doesn't 
> inform about that.
>
> postgres=# SELECT ('{"id": 1}'::json -> 'id')::int;
> ERROR:  cannot cast type json to integer
> LINE 1: SELECT ('{"id": 1}'::json -> 'id')::int;
>
> postgres=# SELECT ('{"id": 1}'::json -> 'id')::text::int;
>  int4
> ------
>     1
> (1 row)
>
>
>



This is not a bug. It is documented and by design.

If you want text, use the ->> operator. That's exactly what it's for.

cheers

andrew



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

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Extent Locks
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: potential bug in JSON