问题描述
我想查找“描述”中包含2或3位数字的实例。
桌子就像
id | description
--- ------------
1 | This is 40cm long.
2 | The dog is black.
我尝试过
SELECT id,description
FROM table
WHERE description LIKE '%[0-9]%' or description LIKE '%[0-9][0-9]%'
我认为应该返回哪个结果
id | description
--- ------------
1 | This is 40cm long.
谢谢
解决方法
在Postgres中,使用正则表达式。匹配1或两位数字(如代码中所示):
WHERE description ~ '[0-9]{1,2}'
这匹配2或3(如描述中所示):
WHERE description ~ '[0-9]{2,3}'
,
您正在将LIKE与正则表达式混淆。您可以采用正则表达式路由,也可以查看SQL标准的SIMILAR TO:
torch.max(batch,dim=1,keepdim=True)
应该为您提供2位或3位数字的描述
来源:https://www.postgresql.org/docs/current/functions-matching.html