gpt4 book ai didi

java - 组织.postgresql.util.PSQLException : ERROR: syntax error at or near ":"

转载 作者:行者123 更新时间:2023-11-29 14:25:44 33 4
gpt4 key购买 nike

我正在从 PgAdmin4 运行成功运行的 SQL 查询,但是当我从我的 Spring Boot 应用程序中使用相同的查询来运行它时,出现错误“org.postgresql.util.PSQLException: ERROR: syntax error at or near ":""

SQL 查询如下所示:

SELECT
student.surname, student.first_name, student.last_name,
jsonb_pretty(elems)
FROM assessment, jsonb_array_elements(assessment.assessment) AS elems
JOIN student ON student.id = (elems->>'student_id')::uuid
WHERE subject_id = 2
AND academy_year_id =3
AND form_id = 2
AND term_id = 1
AND section_id = 4;

这从 PgAdmin4 成功运行。

这是我在我的存储库中的实现

@Query(nativeQuery = true, value = "SELECT\n" +
" student.surname, student.first_name, student.last_name,\n" +
" jsonb_pretty(elems)\n" +
"FROM assessment, jsonb_array_elements(assessment.assessment) AS elems\n" +
"JOIN student ON student.id = (elems->>'student_id')::uuid\n" +
"WHERE subject_id = 2\n" +
"AND academy_year_id =3\n" +
"AND form_id = 2\n" +
" AND term_id = 1\n" +
"AND section_id = 4;")
Object[] getSubjectAssessments();

当我的 API 调用此方法时,我收到此错误消息

org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" 

我不知道我做错了什么。

最佳答案

JPA 无法处理 Postgres 特定的转换运算符 ::

改用cast():

JOIN student ON student.id = cast(elems->>'student_id' as uuid)

关于java - 组织.postgresql.util.PSQLException : ERROR: syntax error at or near ":",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58268321/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com