[英]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.