问题背景
最近给一个项目从mysql迁移到pgsql中去,mysql中的日期大于小于等于操作符可以直接对string生效,会进行自动转换,但是在pgsql下不行,并且会触发"Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp without time zone >= character varying",项目是springboot2+mybatis plus框架,该任务由定时任务执行。
报错信息:
shell
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp without time zone >= character varying
建议:No operator matches the given name and argument types. You might need to add explicit type casts.
位置:64
### The error may exist in com/common/mapper/SysDictTypeMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT COUNT(*) AS total FROM sys_dict_type WHERE (create_time BETWEEN ? AND ?)
### Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp without time zone >= character varying
建议:No operator matches the given name and argument types. You might need to add explicit type casts.
位置:64
; bad SQL grammar []
解决方案
- 传入参数时把数据格式转换为date类型,不可以是string类型