错误:无法匹配没有时区的COALESCE类型bytea和timestamp

时间:2017-10-20 18:30:49

标签: sql spring postgresql

我正在尝试运行此查询,但我收到此错误:

 ERROR: COALESCE types bytea and timestamp without time zone cannot be matched

我想问题出现在这一行:

 COALESCE(:last_timestamp,date_trunc('hour', timestamp '1969-01-01 00:00:00.000000'))

参数:

:last_timestamp

可以为NULL,这就是为什么我这样做的原因

@Query(value="SELECT\n" +
      "  id,\n" +
      "  wristband_records_processed.device_id as deviceId,\n" +
      "  user_id as userId,\n" +
      "  rssi,\n" +
      "  record_timestamp as locationTimestamp,\n" +
      "  beacon_id as beaconId,\n" +
      "  locatable_devices.locatable_type as locatableType,\n" +
      "  coalesce(EXTRACT(EPOCH FROM (record_timestamp - lag(record_timestamp) OVER(order by record_timestamp))),0 )as duration\n" +
      " FROM wristband_records_processed\n" +
      "  LEFT JOIN locatable_devices on locatable_devices.device_id = wristband_records_processed.beacon_id\n" +
      "where user_id = :userId and record_type != 'HANDWASH'\n" +
      "      and rssi >= -85 AND locatable_type != 'UNKNOWN' AND wristband_records_processed.record_timestamp> COALESCE(:last_timestamp,date_trunc('hour', timestamp '1969-01-01 00:00:00.000000')) \n " +
      "OFFSET :offset LIMIT :limit ;", nativeQuery = true)

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

只是让它们相同

COALESCE(date_trunc('hour', :last_timestamp ),
         date_trunc('hour', timestamp '1969-01-01 00:00:00.000000'))

COALESCE(:last_timestamp, timestamp '1969-01-01 00:00:00.000000')