Java 在JDBC中使用unnest(array[someArray])发送三个数组时出现异常
我无法将3个数组发送到SQL语句中,它会引发异常Java 在JDBC中使用unnest(array[someArray])发送三个数组时出现异常,java,postgresql,jdbc,jdbctemplate,Java,Postgresql,Jdbc,Jdbctemplate,我无法将3个数组发送到SQL语句中,它会引发异常 select t.ttt, t.created_date, concat_ws('-',lp.mmm, lp.ccc, lp.eee ) from tasks t join positions p on t.id = p.task_id left join lte_position lp on p.id = lp.id where t.ttt in (:identities) and (lp.mmm, lp.ccc, lp.eee) in ((s
select t.ttt, t.created_date, concat_ws('-',lp.mmm, lp.ccc, lp.eee ) from tasks t
join positions p on t.id = p.task_id
left join lte_position lp on p.id = lp.id
where t.ttt in (:identities) and (lp.mmm, lp.ccc, lp.eee) in
((select mmm,ccc,eee from ((select unnest(array[:mmm]) as mmm, unnest(array[:ccc]) as ccc, unnest(array[:eee]) as eee)) as temp))
order by t.ttt DESC
org.postgresql.util.PSQLException: ERROR: cannot cast type record to integer
Position: 474
我想在mmm
,ccc
,eee
中发送3个数组。当我在Postgres控制台上尝试时,它工作得很好,但是当我在Java代码中尝试时,in抛出了一个异常
select t.ttt, t.created_date, concat_ws('-',lp.mmm, lp.ccc, lp.eee ) from tasks t
join positions p on t.id = p.task_id
left join lte_position lp on p.id = lp.id
where t.ttt in (:identities) and (lp.mmm, lp.ccc, lp.eee) in
((select mmm,ccc,eee from ((select unnest(array[:mmm]) as mmm, unnest(array[:ccc]) as ccc, unnest(array[:eee]) as eee)) as temp))
order by t.ttt DESC
org.postgresql.util.PSQLException: ERROR: cannot cast type record to integer
Position: 474
按照您编写的方式,PostgreSQL认为您的整个参数字符串是一个整数 而不是
unnest(array[:mmm])
使用
但是参数必须看起来像
{1,23,456}
包括支架。这是PostgreSQL中数组的字符串表示形式
附加观察:为什么使用
:mmm
?JDBC参数必须写成?
{1,23456}。如何将此参数与jdbctemplate一起发送?不知道,从未听说过jdbctemplate。我以为问题是关于jaca-Spring JDBC的JDBC.NamedParameterJdbcTemplate的