前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Postgre SQL ERROR:there is no unique or exclusion constraint matching the ON CONFLICT specification

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

作者头像
chimchim
发布2023-10-17 08:54:12
5520
发布2023-10-17 08:54:12
举报

一、问题

使用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.

二、定位问题

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

三、删除主键约束

代码语言:javascript
复制
ALTER TABLE public.table_name  DROP CONSTRAINT table_name_pkey;

四、增加主键约束

代码语言:javascript
复制
ALTER TABLE public.table_name  add primary key (id,col1);

五、检查datax自定义json配置

代码语言:javascript
复制
{
	"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主键约束

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、问题
  • 二、定位问题
  • 三、删除主键约束
  • 四、增加主键约束
  • 五、检查datax自定义json配置
  • 六、总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档