简体   繁体   English

org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误

[英]org.postgresql.util.PSQLException: ERROR: syntax error at or near “:”

I am running an SQL query from PgAdmin4 which runs successfully, but when i take that same query to run it from my Spring Boot application i have an error " org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" "我正在从 PgAdmin4 运行 SQL 查询,该查询成功运行,但是当我从我的 Spring 启动应用程序中执行相同的查询时,我有一个错误“org.ZE4728F444B24839E3F80ADPSQL3829E3F80ADF3839E3F80ADF3839E3F80APSQL3839E3F80ADF3839E3F80ADF3839E3F80ADF3829E3F80ADF3829E38008DD81C2F4D7985ECF6E0CE8AF1D1Z启动应用程序” "

Here is what the SQL query looks like:这是 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;

And this run successfully from PgAdmin4.这从 PgAdmin4 成功运行。

This is my implementation in my Repository这是我在我的存储库中的实现

@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();

And when my API calls this method i get this error message当我的 API 调用此方法时,我收到此错误消息

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

I don't know what I am doing wrong.我不知道我做错了什么。

JPA can't handle the Postgres specific cast operator :: . JPA 无法处理 Postgres 特定的强制转换运算符::

Use cast() instead:使用cast()代替:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引起:org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误 - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" org.postgresql.util.PSQLException:错误:在“with”处或附近出现语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near "with" org.postgresql.util.PSQLException:错误:语法错误在“$ 1”或附近 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1” org.postgresql.util.PSQLException:错误:“ 7”或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “7” org.postgresql.util.PSQLException:错误:“)”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “)” org.postgresql.util.PSQLException:错误:“-”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “-” org.postgresql.util.PSQLException:错误:“(”或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “(” org.postgresql.util.PSQLException:错误:Java 中«,» 附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error near «,» in Java Java 中的错误:org.postgresql.util.PSQLException:错误:语法错误附近; - Error in Java: org.postgresql.util.PSQLException: ERROR: syntax error near ; date_trunc org.postgresql.util.PSQLException:错误:“ $ 1”或附近的语法错误 - date_trunc org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM