Postgre SQL ERROR:there is no unique or exclusion constraint matching the ON CONFLICT specification

目录

一、问题

二、定位问题

三、删除主键约束

四、增加主键约束

五、检查datax自定义json配置

六、总结


一、问题

使用datax从hive推送数据到pg时报错

 ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification  Call getNextException to see other errors in the batch.

 

二、定位问题

从报错内容很明显能看出来是主键约束出了问题,检查一下我们的主键设置

三、删除主键约束

ALTER TABLE public.table_name  DROP CONSTRAINT table_name_pkey;

四、增加主键约束

ALTER TABLE public.table_name  add primary key (id,col1);

五、检查datax自定义json配置

{
	"job": {
		"setting": {
			"speed": {
				"channel": 1
			},
        "errorLimit": {
            "record": 0,
            "percentage": 0.02
            }
		},
		"content": [{
			"reader": {
                    "name": "hdfsreader",
                    "parameter": {
                        "path": "/user/hive/warehouse/db_name.db/table_name",
                        "defaultFS": "hdfs://ip:host",
                        "column": [
                               {
                                "index": 0,
                                "type": "string"
                               },
                               {
                                "index": 1,
                                "type": "string"
                               },
                               {
                                "index": 2,
                                "type": "string"
                               }
                        ],
                        "fileType": "orc",
                        "encoding": "UTF-8",
                        "fieldDelimiter": "\t"
                    }

                },
			"writer": {
                    "name": "postgresqlwriter",
                    "parameter": {
                        "print": true,
                        "encoding": "UTF-8",
                        "username": "u",
                        "password": "p",
                        "column": [
                        "id",
						"col1",
                        "col2"
                    ],
                    "connection": [
                        {
                            "jdbcUrl": "jdbc:postgresql://ip:host/db_name",
                            "table": ["public.table_name"]
                        }
                    ],
                    "writeMode": "update (id,col1)"
					}
                }
            }
        ]
    }
}

ps:我本次的报错原因是datax的主键约束跟pg表结构主键约束不一致导致的555

六、总结

1.检查目标表主键约束

2.检查datax json主键约束

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值