在 h2/postgres 中匹配文字百分比?

Matching literal percent in h2/postgres?

我在数据库列中有以下值:

some%thing

我正在使用 h2 和 postgres,但无法弄清楚为什么这个查询(我在其中转义了 % 以执行文字搜索)与突出显示的行不匹配?:

LIKE 'some\%thing'

因为'value'是一个字符串字面量而不是你的列名。您需要改用双引号。

"value" LIKE 'some\%hing'

一种选择是使用正则表达式:

where value ~ '%'

LIKE 还支持显式转义字符:

where value like '%$%%' escape '$'

或者默认的,\