->>
和->
在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/