简体   繁体   中英

PostgreSQL Parameter error (timestamp with time zone, timestamp without time zone)

I get an error

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

I already found the cause of this error is because the parameter didn't match to => (timestamp without time zone, timestamp without time zone)

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

So, how to match this syntax parameter with this right param => (timestamp without timezone, timestamp without timezone)? I need to match to this, because my framework using this parameter format and I'm not allowed to change the framework.

To force a CAST :

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

Be aware that there are potential time zone conversions that take place when you do this. For more details see the section below:

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

8.5.1.3. Time Stamps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM