首页 文章

Postgres警告:pg_query():查询失败:ERROR:运算符不存在:boolean = integer LINE 1

提问于
浏览
1

我正在使用postgres,我想尝试date_diff,但我得到这个错误

警告:pg_query():查询失败:ERROR:运算符不存在:boolean = integer LINE 1

然后这是我的查询

select id_mitra
      ,company_name 
from ref_mitra
where reject=0 and DATE_DIFF(now(),date_status) > 3 and active='N'

我的查询有什么问题?

2 回答

  • 1

    将值0转换为布尔值:

    select id_mitra
          ,company_name 
    from ref_mitra
    where reject = CAST(0 as boolean) 
    and DATE_DIFF(now(),date_status) > 3 
    and active='N';
    

    或者使用布尔值:

    select id_mitra
          ,company_name 
    from ref_mitra
    where reject = false 
    and DATE_DIFF(now(),date_status) > 3 
    and active='N';
    

    DATE_DIFF()不是PostgreSQL中的标准函数,但也许您使用此名称创建了一个函数 .

  • 2

    您的查询中有两个错误:

    • 您正在将数字( 0 )与 boolean 进行比较

    • Postgres中没有 date_diff() 函数

    假设 date_status 是(真实) date 列,您的查询应如下所示:

    select id_mitra
          ,company_name 
    from ref_mitra
    where reject = false 
      and current_date - date_status > 3 
      and active='N';
    

    now() 返回 timestamp 但是因为你显然想要天数(不是 interval ),你应该使用 current_date 而不是 now() .

    我不确定 date_diff() 究竟是做什么的,也许你需要写 date_status - current_date 以获得相同的行为 .

    而不是 reject = false 你也可以使用 where not reject

相关问题