查找具有字段的行,该字段是搜索字符串的子字符串

dsa*_*sas 5 sql postgresql

给出一个像这样的表格:

id      |    value
-------------------
1       |     food
2       |     foot
3       |     barfoo
4       |     bar
5       |     baz

使用postgres我想从搜索字段的开头找到值字段匹配的所有行.有点像SELECT * FROM table where 'foo' ilike value%

搜索'foo'会返回食物和脚,但不会返回barfoo.

我认为这应该很容易,但我遗漏了一些明显的东西.

Raw*_*ser 6

不应该切换比较吗

where value ilike 'foo%'
Run Code Online (Sandbox Code Playgroud)

编辑

  • 根据原始示例,更改为不区分大小写的“ilike”。

SQL 方言如此之多,灰质存储空间却如此之少。