r - R将tbl对象更新为红移
问题描述
我在 redshift db 中有一个表,我使用 copy_to 命令从 R 更新值。插入到 R 中的变量的类是:
class(df)
[1] "tbl_dbi" "tbl_sql" "tbl_lazy" "tbl"
使用的 copy_to 命令是:
copy_to(acc_conn, df,name = "test_output",temporary = FALSE)
然而,copy_to 命令只插入而不更新。还有其他更新红移表的可能性吗?
解决方案
我写了一篇详尽的博文,解释了从 Amazon Redshift 读取/写入数据的许多细微差别:https ://auth0.com/blog/a-comprehensive-guide-for-connecting-with-r-to-redshift /
特别是,使用 R 读取数据的最佳方法是使用 RPostgres 库,并且我建议使用我创建的 R 包写入数据:https ://github.com/sicarul/redshiftTools
特别是,它具有 rs_upsert_table 函数,该函数使用您的示例执行 data.frame 的 upsert:
rs_upsert_table(df, dbcon=acc_conn, table_name="test_output", bucket="mybucket", split_files=4)
您需要一个 S3 存储桶和 AWS 密钥才能访问它,因为此包上传到 S3,然后将 redshift 定向到该存储桶,这是批量上传数据的最快方式。
推荐阅读
- regex - 如何用正则表达式删除两组字符?
- node.js - Stripe Node JS 集成无错误回调
- gitlab - 使用 Gitlab 多项目管道如何运行特定工作?
- sql - 谷歌大查询中的ST_BUFFER?
- c++ - std::move 是否使指向 unique_ptr 拥有的东西的原始指针无效?
- java - 检测片段中 Recyclerview 上的上下滑动我该怎么做?
- ios - 如何使用 swift 从我的 ios 应用程序通过 WhatsApp 向特定联系人发送消息?
- django - Revealing form fields after checkbox is checked django
- android - 应用程序停止响应向 FireBase 添加数据。获取:解决失败:Lcom/google/common/base/CharMatcher;
- reactjs - 如何在使用 reactjs 构建的 jest Mount 测试中修复组件变量的类型推断?