下面的 PostgreSQL 查詢在 pgAdmin 中可以正常作業。
(select * from posts where id = 1) union (select * from posts);
但是當用 Spring Data JPA 撰寫時,它不起作用。
@Query(value = "(select * from posts where id = 1) union (select * from posts)",
nativeQuery = true)
Page<Post> getPosts(Pageable pageable);
它給出了一個例外
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "where"
Position: 15
我想要兩個選擇陳述句的聯合,但聯合查詢在 JPA 中不起作用。
uj5u.com熱心網友回復:
怎么樣
select
*
from (
(select * from posts where id = 1)
union
(select * from posts)
) as subquery
作為您的查詢?這是一個查詢,框架可以在其中附加其 WHERE 子句而不會出現語法錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/450049.html
標籤:PostgreSQL 休眠 jpa 弹簧数据-jpa
上一篇:如何在GoogleAppEngine上使用jfrog存盤庫中的docker映像?
下一篇:獲取屬于特定學生的表單串列
