嗨我試圖做這個查詢當前年份和第一次發佈的年份是相同的,但它不起作用。我該怎麼做?如何提取「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 –