【发布时间】:2019-06-18 21:25:06
【问题描述】:
我正在尝试以天为单位计算日期之间的差异。 列 snapshot_date 和 date_opened 的数据类型是 Text。我收到一个错误:函数 date_part(unknown, integer) 不存在
SELECT DATE_PART('day', snapshot_date::date -date_opened::date)::number from my_table
【问题讨论】:
-
"datatype is Text for columns snapshot_date 和 date_opened" -- 修复此问题并使用日期类型,如
date或timestamp。 -
你的 postgreSQL 版本是多少?
-
从不将日期值存储在
text(或varchar)列中。这样做是一个非常非常糟糕的主意。
标签: sql postgresql date