嗨我试图做这个查询当前年份和第一次发布的年份是相同的,但它不起作用。我该怎么做?如何提取“where”区域中的timestamp字段的年份并使用postgres 9.6比较当前年份?
我想选择first_published字段(TimeStamp格式)的年份到当前年份的字段。
select distinct name, userid, code, last_updated, first_published
from users
where date_part('year', first_published) = date_part('year', current_date)
and first_published is not null
select distinct name, userid, code, last_updated, first_published
from users
where extract(year from first_published) = date_part(year from current_date)
and first_published is not null
错误:
ERROR: function date_part(unknown, character varying) does not exist
LINE 7: where date_part('year', first_published) = date_part('year',...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function date_part(unknown, character varying) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 298
first_published场的图像
“*不起作用*”不是有效的Postgres错误消息。你需要告诉我们你期望的是什么,你得到什么,为什么你得到的不是你想要的。 –
为什么标题说postgresql ** 9.6 **和标签说** 9.4 **?哪一个? –
我用您的要求更新了问题@a_horse_with_no_name –