我有一个postgres数据库,其中包含一个具有jsonb
列tsent
的表,该表包含对另一列中的文本的目标情感分析的结果.数据的 struct 如下:
CREATE TABLE tbl(id int PRIMARY KEY, tsent jsonb);
INSERT INTO tbl VALUES
(1, '[
{
"class": 0,
"entity": "John Smith",
"sent_no": 0,
"class_label": "negative",
"entity_type": "PER",
"sentiment_prob": 0.95
},
{
"class": 1,
"entity": "University of Illinois",
"sent_no": 0,
"class_label": "neutral",
"entity_type": "ORG",
"sentiment_prob": 0.95
}
]');
它是一个对象数组,因为一个给定的文本可以有多个实体.我想知道如何编写一个查询,检索所有以John Smith为实体的记录,以及那些以John Smith为实体且class_label为负数的记录.
我仍在学习jsonb,知道如何查询是否存在键,但不知道如何查询数组中的任何元素中是否存在键.