sqlite:在模式列表中的地球
我有一个glob
模式(未知长度)的列表,并且希望选择
所有与模式的任何 任何条目。
天真的方法是:
SELECT name, age
WHERE name GLOB 'John*' OR name GLOB 'Mar*'
;
但是,这似乎非常笨拙(尤其是有很多模式)。
进行确切的匹配时,我可以在关键字中使用,例如:
SELECT name, age
WHERE name IN ('John', 'Mary')
;
我想知道,我是否可以使用glob
,例如这样(显然是非 -工作示例):
SELECT name, age WHERE name GLOB IN ('John*', 'Mar*');
I have a list of GLOB
patterns (of unknown length), and would like to SELECT
all entries that match any of the patterns.
The naive approach would be:
SELECT name, age
WHERE name GLOB 'John*' OR name GLOB 'Mar*'
;
However, this seems extraordinarily clumsy (esp. if there are many patterns).
When doing an exact match, I can use the IN
keyword, like so:
SELECT name, age
WHERE name IN ('John', 'Mary')
;
So I wonder, whether I can do something similar with GLOB
, e.g. like this (obviously non-working example):
SELECT name, age WHERE name GLOB IN ('John*', 'Mar*');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用CTE返回所需的所有模式,并且在主要查询中使用
存在
以检查是否有任何匹配:存在
在找到第一个匹配时返回并且不需要检查所有模式。请参阅。
Use a CTE that returns all the patterns that you want and in the main query use
EXISTS
to check if there is any match:EXISTS
returns as soon as it finds the 1st match and does not need to check all the patterns.See the demo.