【问题标题】:DB query error. Code: 42601 Message: syntax_error Cause: ERROR: syntax error at or near "<"数据库查询错误。代码:42601 消息:syntax_error 原因:错误:“<”处或附近的语法错误
【发布时间】:2019-11-06 00:55:20
【问题描述】:

我收到此错误: 数据库查询错误。代码:42601 消息:syntax_error 原因:错误:“

我正在尝试使用“selected_tags”中的标签获取包含最多“节目”的“组织”。


    @SqlQuery("SELECT DISTINCT organisation.id, organisation.name, organisation.type, " +
            "                organisation.logo_asset_id,organisation.address, organisation.status, count(s) " +
            "FROM organisation " +
            "    LEFT JOIN channel c on organisation.id = c.organisation_id " +
            "    LEFT JOIN show s on c.id = s.channel_id " +
            "    WHERE (<selected_tags>) && s.tags " +
            "    GROUP BY organisation.id, organisation.name, organisation.type, " +
            "             organisation.logo_asset_id,organisation.address, organisation.status " +
            "    ORDER BY count(s) DESC " +
            "    LIMIT (:limit) OFFSET (:offset);")
    List<Organisation> findByTags(@BindIn("selected_tags") List<String> tags, @Bind("limit") int limit, @Bind("offset") int offset);

【问题讨论】:

  • WHERE (&lt;selected_tags&gt;) - 你是什么意思?这是专栏吗?
  • 这是 jsql。我正在尝试将 tags 参数绑定到 并将其与 s.tags 进行比较

标签: java sql postgresql


【解决方案1】:

您似乎正在尝试将列表与 JDBI 绑定,但我认为您的 SQL 语句不正确。

正确的应该如下所示:

...
WHERE s.tags IN (<selected_tags>)
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 2021-02-28
    • 2017-02-20
    • 1970-01-01
    相关资源
    最近更新 更多