我有一个简单的 SQL 查询,可以帮助我找到它的值在字段文本中有一些英文字母。
这里是 SQL :
select id,field1
from mytable
where mytable like '[A-Z]'
该查询在 MS-ACCESS 数据库中运行良好,但在 QGIS 和 postgis 查询的 DB MANAGER 上运行不佳,因为我认为 Postgres 无法识别字母列表 [A-Z]。
如果我使用这个:
select id,field1
from mytable
where mytable like '%A%'
or mytable like '%B%'......
然后它起作用了,但我不喜欢这种方法。
在 Postgres 中:
select public.mytable.id,public.mytable.field1
from mytable
where public.mytable.mytable like '[A-Z]'
我尝试使用:
'*[A-Z]*'
'%[A-Z]%'
但这并没有改变什么
最佳答案
您可以使用 ~
运算符来评估正则表达式:
SELECT id, field1 FROM mytable WHERE mytable ~ '[A-Z]'
关于SQL 查询在 postgresql 数据库中不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46592738/