是否有通配符搜索解决方案可以让我搜索给定的字符串但允许 2 个字符在 Snowflake 中为 wrong/missing/blank?

Is there a wildcard search solution that can allow me to search for a given string but allow 2 characters to be wrong/missing/blank in Snowflake?

我对正则表达式的概念还很陌生,我正在寻找一种通配符搜索解决方案,它允许字符串的 2 个或更少字符在 Snowflake 中成为 wrong/missing/blank。 例如,如果我有 table 的篮球运动员姓名列,例如下面的“lebron james”、'carmelo anthony'、'kobe bryant'是我想从另一个 table(消费者的搜索查询)匹配的结果 'lebron james':

'lebrn james'(缺少'o')

'lebronjames'(在 fn 和 ln 之间缺少一个 space)

'lebrn jme'(缺少 'o' 和 'a')

'lebron james'(精确匹配)

有好心人提供一些指导吗?

EDITDISTANCE 就是你要的:

with input(str) as (
    select * from values
    ('lebrn james'), ('lebronjames'), ('lebrn jme')
), targets(str) as (
    select * from values
    ('lebron james'), ('carmelo anthony'), ('kobe bryant')
)
select i.str, t.str, editdistance(i.str, t.str)
from input i
cross join targets t;

给出:

STR STR_2 EDITDISTANCE(I.STR, T.STR)
lebrn james lebron james 1
lebrn james carmelo anthony 14
lebrn james kobe bryant 10
lebronjames lebron james 1
lebronjames carmelo anthony 13
lebronjames kobe bryant 10
lebrn jme lebron james 3
lebrn jme carmelo anthony 13
lebrn jme kobe bryant 9