Pregunta

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?

¿Fue útil?

Solución

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top