相关疑难解决方法(0)

如何将CSV文件数据导入PostgreSQL表?

如何编写从CSV文件导入数据并填充表的存储过程?

csv postgresql postgresql-copy

565
推荐指数
14
解决办法
73万
查看次数

操作错误:(psycopg2.OperationalError)无法将主机名“143@postgres”转换为地址:未知服务器错误

我想导入一个大的 csv 文件,而不需要先将该 csv 文件创建表到 postgresql 中。在 stackoverflow 上搜索时,一位用户建议使用以下代码:

from sqlalchemy import create_engine
engine = create_engine('postgresql://username:password@localhost:5432/mydatabase')
df.to_sql('table_name', engine)
Run Code Online (Sandbox Code Playgroud)

基于此,我根据我的 postgresql 的信息编写了以下代码,其中用户名 =“postgres”,密码 =“Katherine@412”:

from sqlalchemy import create_engine
engine = create_engine('postgresql://[postgres]:Katherine@412@postgres:5432/covid_deaths.csv')
df.to_sql('covid_deaths_owid', engine)
Run Code Online (Sandbox Code Playgroud)

但是它给了我以下错误:

OperationalError: (psycopg2.OperationalError) could not translate host name "412@postgres" to address: Unknown server error
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我我做错了什么吗?

csv postgresql sqlalchemy

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

csv ×2

postgresql ×2

postgresql-copy ×1

sqlalchemy ×1