【发布时间】:2021-03-28 06:07:12
【问题描述】:
我正在使用 Spring Boot/Framework/JPA 来读取 PostgreSQL 数据库表。但是,我有一种情况,我想从 TIMESTAMP WITH TIME ZONE / OffsetDateTime 的列中进行选择,但我只想比较日期,而不是时间。
根据我在谷歌搜索后发现的内容,我尝试了以下(在 Kotlin 中),但这两个都给了我语法错误,说它不需要左括号。如果没有这些函数,它会匹配日期和时间。
@Query(
"""select odi from on_deck_inventory odi
where odi.sku = :sku
and odi.storeId = :storeId
and date(odi.transactionDate) = :transactionDate
and odi.restocked = :restocked
"""
)
@Query(
"""select odi from on_deck_inventory odi
where odi.sku = :sku
and odi.storeId = :storeId
and date = cast(:transactionDate as date)
and odi.restocked = :restocked
"""
)
JPQL 似乎不允许在查询中使用任何类型的函数。有没有其他方法可以做到这一点?
【问题讨论】:
标签: spring-boot jpa spring-data-jpa