Postgres SQL中的`->>`和`->`有什么区别? [英] What is the difference between `->>` and `->` in Postgres SQL?
本文介绍了Postgres SQL中的`->>`和`->`有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在SQL中->>
和->
有什么区别?
What is the difference between ->>
and ->
in SQL?
在此线程中(检查字段是否以json类型存在列postgresql ),回答者基本上建议使用,
In this thread (Check if field exists in json type column postgresql), the answerer basically recommends using,
json->'attribute' is not null
而不是
json->>'attribute' is not null
为什么使用单箭头而不是双箭头?以我有限的经验,两者都做同样的事情.
Why use a single arrow instead of a double arrow? In my limited experience, both do the same thing.
推荐答案
->
返回json(b)
,而->>
返回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
这篇关于Postgres SQL中的`->>`和`->`有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文