python - 将数据从 csv 插入 Postgres 表时出错
问题描述
我在 AWS S3 中上传了一个 csv 文件,我计划使用以下代码更新 Postgres DB 中的表
cursor.execute("""export PGPASSWORD='db_password'; psql -h hostname -U username -d db_name -c "\COPY table_name FROM 's3://filepath.csv' with DELIMITER ','""")
这会引发错误:
psycopg2.errors.SyntaxError: syntax error at or near "export"
LINE 1: export PGPASSWORD='db_password'; psql -h hostname
解决方案
该命令是 bash 命令,而不是 postgres 命令。
推荐阅读
- java - 错误:cvc-elt.1:找不到元素“bean”的声明
- python - 为什么我的 SVD 计算与 numpy 对该矩阵的 SVD 计算不同?
- mysql - MySQL 中的并发插入和竞争条件
- python - 通过删除异常值来改进 R2-python
- c# - 在 C# 中响应特定 HTTP POST 请求的服务器
- excel-2016 - excel 2016中的填充空格
- c - C - 中方随机数生成器
- spring-cloud-stream - 使用 `@AutoConfigureAfter(TraceAutoConfiguration.class)` 时缺少 bean 'zipkin2.reporter.Sender'
- java - 如何使用 Spring“注入”结构化配置信息?
- .net - 为什么 Serilog 不使用 WriteTo.MSSqlServer 接收器登录到表?