我有一个PG表,其字段类型为char(10)[]。
我需要使用Mule流中的值更新表中的记录。
所以,我做了这样的事情:
flowVars.test=['aaa', 'bbb',ccc'];然后,我正在尝试提交这样的更新语句:
update tab1 set fld1=#[flowVars.test]它失败了,错误:
Cannot cast an instance of java.util.ArrayList to type Types.ARRAY我的理解是在这种情况下应该使用SQL数组,但我无法弄清楚如何在流中获取这样一个数组的实例以及如何在MEL中使用它。
有人可以建议吗?
谢谢,
I have a PG table with a field of type char(10)[].
I need to update a record in the table with values from a Mule flow.
So, i did something like this:
flowVars.test=['aaa', 'bbb',ccc'];Then, I'm trying to submit an update statement like this:
update tab1 set fld1=#[flowVars.test]it's failing with the error:
Cannot cast an instance of java.util.ArrayList to type Types.ARRAYMy understanding is that SQL array should be used in this scenario but I can't figure out how to get an instance of such an array in a flow and how to work with it in MEL.
Can someone please advise?
Thank you,
最满意答案
有许多消息来源建议使用Connection#createArrayOf() 。 但我不知道如何在数据库连接器中使用它。
但是,为此我会做这个解决方案:
将ArrayList转换为String。 它应该形成为: {value1, value2, ...} 将数据库查询类型从参数化更改为动态 更新SQL查询成为: update tab1 set fld1 = '#[flowVars.test]' 。 此查询类型需要额外的单引号。最后,通过使用以下配置,我可以更新字符类型(10)[]的字段:
<expression-transformer expression="#[flowVars.test = ['aaa', 'bbb', 'ccc'].toString().replace('[', '{').replace(']', '}')]" doc:name="Expression"/> <db:update config-ref="Postgre_Database_Configuration" doc:name="Database"> <db:dynamic-query><![CDATA[update tab1 set fld1 = '#[flowVars.test]']]></db:dynamic-query> </db:update>Ok, I've found an answer in MuleSoft doc. Starting from version 3.6 DB connector supports custom types and allows defining mapping between SQL arrays and structures and custom user classes. It's documented here .
更多推荐
发布评论