【问题标题】:PostgreSQL Parameter error (timestamp with time zone, timestamp without time zone)PostgreSQL 参数错误(带时区的时间戳,不带时区的时间戳)
【发布时间】:2020-10-26 09:00:17
【问题描述】:

我收到一个错误

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

我已经找到这个错误的原因是因为参数不匹配=>(timestamp without time zone, timestamp without time zone)

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

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

【问题讨论】:

  • postgres中没有MONTHS_BETWEEN函数Doc
  • 它的自定义函数是我们在 postgre 模式中创建的作为框架的函数,正如我所说的,我想将参数与之匹配

标签: java postgresql hibernate


【解决方案1】:

强制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。时间戳

【讨论】:

    猜你喜欢
    • 2021-09-22
    • 2011-08-18
    • 2013-03-27
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2014-02-12
    • 2010-11-10
    相关资源
    最近更新 更多