在休眠状态下获取具有时区值的itimestamp

时间:2018-08-02 14:50:05

标签: postgresql hibernate spring-boot

我正在将Hibernate和Spring Boot与Postgres一起使用。我有一个time with time zone column和另一个date列。我尝试将这两列相加以获得timestamp with timezone value。但是使用休眠查询仅返回timestamp without time zone。有什么办法可以达到同样的效果

我的查询就像

@Query(value = "select date_col + time_with_timestamp_column from myTable" , nativeQuery = true) Timestamp fetchvalue();

2 个答案:

答案 0 :(得分:3)

如果您使用的是Spring Data,则可以通过@Query(..., native=true)使查询成为本地查询。这应该导致查询以实际的SQL而不是JPQL的形式执行,这可能会解决类型问题

答案 1 :(得分:0)

这有用吗?

select to_char(current_date,'DD/MM/YYYY') as newdate, to_char(current_date,'DD/MM/YYYY')||' 13:03:00' as text_datetime, to_timestamp( to_char(current_date,'DD/MM/YYYY')||' 13:03:00', 'DD/MM/YYYY HH24:MI:SS')::timestamp with time zone