简体   繁体   English

PSQLException:错误:“。”处或附近的语法错误

[英]PSQLException: ERROR: syntax error at or near "."

I'm using Java 8, Spring Boot, and PostgreSQL.我正在使用 Java 8、Spring 引导和 PostgreSQL。

I have the following query我有以下查询

@Query(value = "select mc from MasterCourse mc " +
            "where mc.institution.guid = :institutionGuid or mc.consortium = true " +
            "and (:searchStr in (mc.tags) " +
            "or lower(mc.name) like concat('%', lower(:searchStr),'%') " +
            "or lower(mc.description) like concat('%', lower(:searchStr),'%') " +
            "or (:searchStr) in (mc.categories) " +
            "or (:searchStr) in (mc.levels)"+
            "or mc.authorGuid in (:authorGuids))"

and it is giving me an error PSQLException: ERROR: syntax error at or near "."它给了我一个错误PSQLException: ERROR: syntax error at or near "."

I can't seem to figure out what is causing this.我似乎无法弄清楚是什么原因造成的。 It does not appear to be any reserved words.它似乎不是任何保留字。

Any help would be appreciated.任何帮助,将不胜感激。 If you need additional information, please let me know and I can get that asap.如果您需要更多信息,请告诉我,我会尽快得到。

EDIT:编辑:

So I turned on debug logs and got this executed SQL.所以我打开了调试日志并得到了这个执行 SQL。 It looks like it's not liking my and (:searchStr in (mc.tags) . mc.tags appears to just be returning a (.). I'm guessing this is because of the fact that tags is a list of objects, not just strings.看起来它不喜欢我的and (:searchStr in (mc.tags) 。mc.tags 似乎只是返回一个 (.)。我猜这是因为标签是一个对象列表,而不是只是字符串。
I'm trying to match the searchStr on the "name" field of the tags.我正在尝试在标签的“名称”字段上匹配 searchStr。 Any ideas on how to achieve this?关于如何实现这一目标的任何想法?

where mastercour0_1_.institution_id=institutio1_.id and 
mastercour0_.id=tags2_.master_course_id and tags2_.tag_id=tag3_.id and mastercour0_.id=categories4_.master_course_id and 
categories4_.category_id=category5_.id and 
mastercour0_.id=levels6_.master_course_id and 
levels6_.level_id=level7_.id and (institutio1_.guid=? or mastercour0_.consortium=true 
and (? in (.)) 
or lower(mastercour0_.name) like ('%'||lower(?)||'%') 
or lower(mastercour0_.description) like ('%'||lower(?)||'%') 
or ? in (.) or ? in (.) or mastercour0_.author_guid in (null))
  1. concat only takes two arguments You can use the || concat 只需要两个 arguments可以用|| operator instead of concat function, but that's personal preference.运算符而不是 concat function,但这是个人喜好。
  2. you're missing a space at the end of the second to the last line (mc.levels)"+您在倒数第二行末尾缺少一个空格(mc.levels)"+

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

相关问题 PSQLException: 错误: 语法错误在或附近 - PSQLException: ERROR: syntax error at or near PSQLException: 错误: "$1" 处或附近的语法错误 - PSQLException: ERROR: syntax error at or near "$1" PSQLException:位于或“实体”附近的语法错误 - Spring Boot - PSQLException: Syntax Error near at or “Entity” - Spring Boot 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 引起: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:错误:“:”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “:”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM