Nifi使用PutSQL向PostgreSQL写入时报批量更新失败如何解决?
PutSQL写入PostgreSQL分号语法错误排查解决方法
完整报错信息:
PutSQL[id=c47b762a-1000-59c4-a833d62c53d3] Failed to update database due to a failed batch update, Batch entry 0 INSERT INTO mytable(filecount, linecount) VALUES(539, 471557) was aborted:ERROR: syntax error at or near ";" Position 52 call getNextException to see other errors in the batch. There were a total of 1 Flowfiles that succeeded, and 0 that were not execute and will be routed to retry;;java.sql.BatchUpdateException:Batch entry 0 INSERT INTO mytable(filecount, linecount) VALUES(539, 471557) was aborted:ERROR: syntax error at or near ";" Position 52 call getNextException to see other errors in the batch
排查解决步骤
- 检查ReplaceText处理器输出的最终SQL内容:PutSQL执行SQL时不需要语句末尾的分号
;,报错日志中展示的SQL为截断内容,实际生成的SQL末尾大概率多携带了分号。你可以导出PutSQL处理器前的FlowFile内容,查看完整SQL,如果确实携带末尾分号,修改ReplaceText的替换规则删除分号即可。 - 校验PutSQL处理器配置:
- 确认
Support Fragmented Transactions参数为关闭状态,开启该参数时如果SQL携带分号会触发语法解析错误 - 确认PostgreSQL JDBC驱动版本适配PostgreSQL 12.4:NiFi 1.12.1默认携带的驱动版本可能过低,建议升级驱动到42.2.23及以上的pg12适配版本
- 可临时将
Batch Size参数设置为1,排除批量提交时多语句拼接引入的额外分号问题
- 确认
- 手动验证SQL有效性:将导出的完整SQL复制到psql命令行或pgAdmin中直接执行,如果手动执行也报错,直接修正对应语法问题即可。
内容的提问来源于stack exchange,提问作者Justin Coulibaly
相关产品推荐
相关产品推荐

