如何查询jsonb字段类型的jarray?

How to query jarray in jsonb field type?

我在 table 中有一个 jsonb 字段类型,它包含 JArray:

[
  {
    "code": "F01",
    "name": "Apple"
  },
  {
    "code": "F02",
    "name": "Orange"
  },
  {
    "code": "F03",
    "name": "Banana"
  }
]

我尝试根据代码进行查询,并希望得到如下名称:

select a.myarray 水果名称 where a.myarray ->> 'code' = 'F02'

但是它returns是空的

我错过了什么?

select j ->> 'name' 
from jsonb_array_elements(
'[
  {"code": "F01","name": "Apple"},
  {"code": "F02","name": "Orange"},
  {"code": "F03","name": "Banana"}
]'::jsonb) j
where j ->> 'code' = 'F02';

用实际值替换文字 JSON 文本。