| From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
|---|---|
| To: | Szymon Guz <mabewlun(at)gmail(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: potential bug in JSON |
| Date: | 2013-05-28 15:51:53 |
| Message-ID: | 51A4D299.7060501@dunslane.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Josh Berkus | 2013-05-28 15:53:24 | Re: potential bug in JSON |
| Previous Message | Merlin Moncure | 2013-05-28 15:49:44 | Re: Extent Locks |