在EXTRACT中转换时出现语法错误

时间:2014-11-18 20:58:36

标签: sql postgresql

我只是试试这个,我的tdate语法错误(它是DATE类型)

select *
from treatment
where  EXTRACT(month FROM cast (date as TIMESTAMP) tdate) = EXTRACT(month FROM cast (date as TIMESTAMP) current_date)

有人可以帮帮我.. ?? 感谢!!!!

2 个答案:

答案 0 :(得分:0)

这是你要找的东西:

select *
from treatment
where EXTRACT(month FROM cast (tdate as TIMESTAMP)) = 
      EXTRACT(month FROM cast (current_date as TIMESTAMP))

cast(field as type)应该是cast(date as type)

答案 1 :(得分:0)

我不认为你需要打扰任何一个字段,因为你应该能够直接从两者中提取月份。我会尝试:

select * 
from treatment 
where extract(month from tdate) = extract(month from current_date)