gpt4 book ai didi

sql - Postgresql 中的 `->>` 和 `->` 有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 12:47:59 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com