【问题标题】:Matching literal percent in h2/postgres?匹配 h2/postgres 中的文字百分比?
【发布时间】:2020-03-30 12:16:37
【问题描述】:

我在 db 列中有以下值:

some%thing

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

LIKE 'some\%thing'

【问题讨论】:

标签: sql postgresql h2


【解决方案1】:

因为'value' 是字符串文字,而不是列名。您需要改用双引号。

"value" LIKE 'some\%hing'

【讨论】:

    【解决方案2】:

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

    where value ~ '%'
    

    LIKE 还支持显式转义字符:

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

    或者默认的\

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-04
      • 2021-02-05
      • 2019-07-07
      • 2021-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      相关资源
      最近更新 更多