【问题标题】:How do I escape a single quote in Presto?如何在 Presto 中转义单引号?
【发布时间】:2018-03-02 02:12:06
【问题描述】:

如何在 Presto 中转义 '(单引号)?

这是我尝试使用它的地方

select count(*) as count 
from uploads
where title not in ('Driver's License')

我尝试了通常的转义:'Driver\'s License'"Driver's License"E'Driver\'s License',但似乎没有任何效果。 Presto 的文档含糊不清。有人知道吗?

【问题讨论】:

  • 在(标准)SQL 中为'Driver''s License'
  • 成功了!谢谢!

标签: sql presto


【解决方案1】:

a_horse_with_no_name 提供的答案是使用另一个'

'Driver''s License'

【讨论】:

    【解决方案2】:

    用单引号两次代替需要转义的单引号:

    select count(*) as count 
    from uploads
    where title not in ('Driver''s License')
    

    【讨论】:

      【解决方案3】:

      在需要单引号的任何地方使用CHR(39) 字符函数。使用concat 函数或使用双管道||

      select count(*) as count 
      from uploads
      where title not in (concat('Driver', CHR(39), 's License'))
      

      select count(*) as count 
      from uploads
      where title not in ('Driver' || CHR(39) || 's License')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-02
        • 2012-04-11
        • 2010-10-27
        • 2012-09-13
        • 1970-01-01
        相关资源
        最近更新 更多