PSQLException:错误:运算符不存在:bigint = text []

问题描述 投票:0回答:1

在postgres DB和MySQL DB中查看分辨率正常

I / P:字符串ordIds =“ 343,21,343”;

Map fetchDataSource(String orgIds){

    ResultSet resultSet = null;
    PreparedStatement statement = null;
    String str[] = orgIds.split(",");
    List<Integer> orgIdList = new ArrayList<Integer>();

    Map<String, String> dataSourceMap = new LinkedHashMap<String, String>();
    orgIdList = Arrays.asList(str).stream().map(Integer::valueOf).collect(Collectors.toList());
    String query = "select ds.ds_path,string_agg(org.organization_id::text, ',') as org_id from c_organization org join org_ds_detail ds on org.org_ds_detail_id = ds.org_ds_detail_id where org.organization_id in (?) GROUP BY ds.ds_path";
    //String queryIN = orgIdList.stream().map(orgId -> String.valueOf(orgId)).collect(Collectors.joining(",", "(", ")"));

    try {
        Connection connection = DBConnection.getInstance("CLINICS_GLOBAL");
        statement = connection.prepareStatement(query);
        **Array orgIdsInArray = connection.createArrayOf("text",orgIdList.toArray());
        statement.setArray(1, orgIdsInArray);**
        logger.info("Executing Query:" + query);
        resultSet = statement.executeQuery();
        while (resultSet.next()) {
            dataSourceMap.put(resultSet.getString(1), resultSet.getString(2));
        }

    } catch (SQLException e) {
        logger.info("Exception:" + e);
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            statement.close();
            resultSet.close();
            DBConnection.closeConnection();
        } catch (SQLException e) {
            logger.info("Exception while closing connection:" + e.getMessage());
            e.printStackTrace();
        }
    }
    return dataSourceMap;
}

异常(日志):

13:16:16,217 INFO  [DataSourceConnection] (default task-2) Exception:org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = text[]
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 190
13:16:16,219 ERROR [stderr] (default task-2) org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = text[]
13:16:16,219 ERROR [stderr] (default task-2)   Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
13:16:16,220 ERROR [stderr] (default task-2)   Position: 190
13:16:16,221 ERROR [stderr] (default task-2)    at 
java postgresql jdbc
1个回答
0
投票

好吧,正如错误消息所述,您正在传递text[]数组,并尝试将其与bigint值进行比较。您希望Long.valueOf(1) == new String[] {"1", "2"}能在Java中工作吗?

您需要创建一个bigint数组:

Array orgIdsInArray = connection.createArrayOf("bigint",orgIdList.toArray());

并且您需要更改将列与数组进行比较的运算符:

where org.organization_id = any (?)
© www.soinside.com 2019 - 2024. All rights reserved.