如何将日期转换为字符串以便运行此查询?

时间:2014-09-23 19:59:25

标签: postgresql

我试图在postgresql中运行以下查询:

select * from movies where release_date = current_date;

它响应以下错误:

ERROR:  operator does not exist: character varying = date
LINE 1: select * from movies where release_date = current_date;
                                                ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

似乎我需要将current_date函数返回的日期转换为字符串,以便比较起作用。我该怎么做?

2 个答案:

答案 0 :(得分:0)

试试这个:

select * from movies where release_date::date = current_date;

SQLFiddle

答案 1 :(得分:0)

假设您的release_date列可以投放到某个日期,那么您最好选择:

select * from movies where cast(release_date as date) = current_date;

CAST功能是SQL-92 standard的一部分,可以让您的查询在多个平台上移植。