我正在尝试使用sqoop命令插入到postgreSQL DB中。
sqoop export --connect jdbc:postgresql://10.11.12.13:1234/db --table table1 --username user1 --password pass1--export-dir /hivetables/table/ --fields-terminated-by '|' --lines-terminated-by '\n' -- --schema schema
如果没有主键约束,则工作正常。我想同时插入新记录和更新旧记录。
我努力了
--update-key primary_key
这仅更新数据库中同时存在的那些主键(hive和postgreSQL。不插入)--update-mode allowinsert
-这仅插入--update-key primary_key --update-mode allowinsert
-这会导致错误ERROR tool.ExportTool: Error during export: Mixed update/insert is not supported against the target database yet
谁能帮我写sqoop命令,该命令将数据插入并更新到postgreSQL?
最佳答案
根据我的互联网搜索,不可能直接对postgreSQL DB进行插入和更新。相反,您可以在postgreSQL中创建一个storedProc /功能,然后可以在那里发送数据。
sqoop export --connect <url> --call <upsert proc> --export-dir /results/bar_data
Stored proc/function应该同时执行Update和Insert。
链接1-https://issues.apache.org/jira/browse/SQOOP-1270
链接2-PLPGSQL-UPSERT-EXAMPLE
关于postgresql - 如何使用sqoop命令同时插入和更新到PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30887575/