Postgres SQL中的\`->>\`和\`->\`有什么区别?

新手上路,请多包涵

SQL中的 ->>-> 有什么区别?

在这个线程中( 检查字段是否存在于 json 类型列 postgresql 中),回答者基本上建议使用,

 json->'attribute' is not null

代替,

 json->>'attribute' is not null

为什么使用单箭头而不是双箭头?以我有限的经验,两者都做同样的事情。

原文由 tim_xyz 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.3k
1 个回答

-> 返回 json(或 jsonb)和 ->> 返回 text

 with t (jo, ja) as (values
    ('{"a":"b"}'::jsonb,('[1,2]')::jsonb)
)
select
    pg_typeof(jo -> 'a'), pg_typeof(jo ->> 'a'),
    pg_typeof(ja -> 1), pg_typeof(ja ->> 1)
from t
;
 pg_typeof | pg_typeof | pg_typeof | pg_typeof
-----------+-----------+-----------+-----------
 jsonb     | text      | jsonb     | text

原文由 Clodoaldo Neto 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题