[英]PostgreSQL: How to use -> and ->> to search SQL JSON?
[英]how to search values in json field in sql (postgresql)
假設我有一個名為關鍵字的列,其值如['wood', 'grass', 'tree', 'plant']
,現在我如何查詢該數組是否包含wood
或grass
或both of them
我的解決方案(這里我使用文本字符串並搜索它)
select * from table where keywords_column ~* 'wood';
但僅限於一個詞。 如果我能在 knex.js 或 Adonis Lucid 中獲得解決方案,那就太好了
我認為這可能有效,但我沒有測試它:
select * from table where keywords_column ~* 'wood' or keywords_column ~* 'grass';
我會這樣做:
SELECT * from table WHERE column SIMILAR TO '(wood |grass |tree |plant )%';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.