The PostgreSQL documentation for JSON functions lists both both -> and ->>.

However, it's not clear to me what the difference is between them.

Can anyone provide an explanation with more examples?

有帮助吗?

解决方案

The first returns json and the second text:

select
    '[1,2,3]'::json->2 as "->",
    pg_typeof('[1,2,3]'::json->2) as "-> type",
    '[1,2,3]'::json->>2 as "-->",
    pg_typeof('[1,2,3]'::json->>2) as "--> type"
;
 -> | -> type | --> | --> type 
----+---------+-----+----------
 3  | json    | 3   | text
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top