我试图在postgress中找出两个日期之间的区别,
select TO_TIMESTAMP(f_time)-TO_TIMESTAMP(s_time),date from my_table where tId='txt' group by s_time,date;
我可以在pgAdmin中获得结果,并将数据类型与interval
相同。
在java中,我遇到以下异常。
[org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-2) Bad value for type double : 00:16:40
[stderr] (default task-2) javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute query
[stderr] (default task-2) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
[stderr] (default task-2) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
[stderr] (default task-2) at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
[stderr] (default task-2) at .services..(.java:34)
[stderr] (default task-2) at .$Proxy$_$$_WeldClientProxy.(Unknown Source)
[stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[stderr] (default task-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[stderr] (default task-2) at java.lang.reflect.Method.invoke(Method.java:606).
我可以将数据类型更改为文本吗?
答案 0 :(得分:0)
最后,我通过将数据类型转换为text
来解决此问题,如下所示,
cast (((TO_TIMESTAMP(f_time))-(TO_TIMESTAMP(s_time))) as text)