我正在使用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'
我的查询有什么问题?
将值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中的标准函数,但也许您使用此名称创建了一个函数 .
您的查询中有两个错误:
您正在将数字( 0 )与 boolean 进行比较
0
boolean
Postgres中没有 date_diff() 函数
date_diff()
假设 date_status 是(真实) date 列,您的查询应如下所示:
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() .
now()
timestamp
interval
current_date
我不确定 date_diff() 究竟是做什么的,也许你需要写 date_status - current_date 以获得相同的行为 .
date_status - current_date
而不是 reject = false 你也可以使用 where not reject
reject = false
where not reject
2 回答
将值0转换为布尔值:
或者使用布尔值:
DATE_DIFF()不是PostgreSQL中的标准函数,但也许您使用此名称创建了一个函数 .
您的查询中有两个错误:
您正在将数字(
0
)与boolean
进行比较Postgres中没有
date_diff()
函数假设
date_status
是(真实)date
列,您的查询应如下所示:now()
返回timestamp
但是因为你显然想要天数(不是interval
),你应该使用current_date
而不是now()
.我不确定
date_diff()
究竟是做什么的,也许你需要写date_status - current_date
以获得相同的行为 .而不是
reject = false
你也可以使用where not reject