PostgreSQL参数错误(带时区的时间戳,不带时区的时间戳)

时间:2020-10-26 09:00:17

标签: java postgresql hibernate

我遇到错误

Caused by: org.postgresql.util.PSQLException: ERROR: function months_between(timestamp with time zone, timestamp without time zone) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 310

我已经发现此错误的原因是因为参数与=>不匹配(没有时区的时间戳,没有时区的时间戳)

TRUNC(MONTHS_BETWEEN (date_trunc('day', now()), people.original_date_of_hire) / 12) masa_bekerja_year, ");

那么,如何将此语法参数与此正确的param匹配=>(没有时区的时间戳,没有时区的时间戳)?我需要对此进行匹配,因为我的框架使用此参数格式,并且不允许更改框架。

1 个答案:

答案 0 :(得分:0)

强制CAST

TRUNC(MONTHS_BETWEEN (date_trunc('day', now())::timestamp, people.original_date_of_hire::timestamp) / 12) masa_bekerja_year, ");

请注意,执行此操作时可能会发生时区转换。有关更多详细信息,请参见以下部分:

https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-TIMEZONES

8.5.1.3。时间戳