如何作为JSON获得后Gresql查询结果
我在表格中有文本字段,我想使用条件的地方查询此字段:我想查询所有至少一个单词as as as s sords as s of单词并返回JSON的记录,并返回了这样的JSON:
text
The employee was fired today
He likes chocolate a lot
She eat chocolate today
Car was stolen yesterday
select * from tbl
where text CONTAINS ANY ['today','likes','eat']
Guestered输出1:
{"id":"1", "text":"The employee was fired today", "tag":"today"}
{"id":"2", "text":"He likes chocolate a lot", "tag":"likes"}
{"id":"3", "text":"She eat chocolate today", "tag":["today","eat"]}
Desidered输出2:
text tag tag_counts
The employee was fired today today 1
He likes chocolate a lot likes 1
She eat chocolate today eat, today 2
我想获得这些输出中的任何一个。
我已经发现我可以使用在其中('今天','likes','eat')
,但如果可能的话,我找不到如何在任何所需的输出中获得结果。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我选择了文本列的列名
单词
。 “文本”是一个基本的类型名称,因此太令人困惑了。对于带有平原
文本
列的给定表格:更简单的文本数组(
text []
)表格从:db<> fiddle
可以用 gin索引支持。
text
列的表达式索引:text []
:See:
I chose the column name
words
for the text column. "text" is a basic type name and too confusing as such.For your given table with a plain
text
column:Simpler with a text array (
text[]
) in the table to begin with:db<>fiddle here
Can be supported with a GIN index. An expression index for the
text
column:Simpler, yet again, for
text[]
:See: