->>
和->
在SQL中有什么区别?
在本帖(Check if field exists in json type column postgresql)中,答主基本推荐使用,
json->'attribute' is not null
而不是,
json->>'attribute' is not null
为什么使用单箭头而不是双箭头?以我有限的经验,两者都做同样的事情。
最佳答案
->
返回 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
关于sql - Postgresql 中的 `->>` 和 `->` 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38777535/
相关文章:
ruby-on-rails-3 - 如何使用 ActiveModel::Serializers 为同
javascript - D3.js:使用图像(在数据中指定文件名)作为轴上的刻度值
javascript - 有没有一种快速的方法可以在文本编辑器中将 JavaScript 对象转换为
json - 如何将 JSON 文件导入 TypeScript 文件?
javascript - 使用 jQuery 检查 JSON 对象中是否存在键
java - Jackson - 反序列化 JSON 字符串 - TypeReference 与 T