【问题标题】:PostgreSQL search in table with type timestamp without timezonePostgreSQL在没有时区的时间戳类型的表中搜索
【发布时间】:2021-06-12 15:28:51
【问题描述】:

我需要使用字符串搜索 Postgres 表中的所有列。但这会导致类型为“timestamp without timezone”的列出错; 它显示错误:“错误:运算符不存在:没有时区的时间戳~~未知”

【问题讨论】:

    标签: php jquery sql postgresql search


    【解决方案1】:

    您正在尝试使用LIKE 运算符(内部为~~)搜索timestamp。这是行不通的,因为日期时间数据类型不存在该运算符。

    您必须将timestamp 转换为字符串数据类型:

    WHERE CAST(timestamp_col AS text) LIKE '2021-%'
    

    或者,更好的是,明确地将其格式化为字符串:

    WHERE to_char(timestamp_col, 'YYYY-MM-DD HH24:MI:SS') LIKE '2021-%'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 2014-02-12
      • 2018-07-10
      • 2011-07-15
      相关资源
      最近更新 更多