【问题标题】:Pushing dataframe to postgres using sqlalchemy and psycogp2使用 sqlalchemy 和 psycopg2 将数据帧推送到 postgres
【发布时间】:2017-10-25 10:20:39
【问题描述】:

我正在尝试将数据帧写入 postgres 。对于使用的 DBAPI 是 psycogp2。

localconn='postgresql+psycopg2://postgres/PSWD@localhost:5432/localPG'
localEng=engine.create_engine(localconn)
df.to_sql("DUMMY", localEng)

但是它的抛出错误(psycopg2.OperationalError) could not translate host name postgres to address: Name or service not known

localPG 是数据库名称。

我哪里做错了?

【问题讨论】:

    标签: python python-2.7 postgresql


    【解决方案1】:

    你写的格式不对,使用如下:

    localEng = create_engine('postgresql+psycopg2://[user]:[pass]@[host]:[port]/[schema]', echo=False)
    

    当然,您应该用等效的数据库凭据替换括号之间的每个参数。

    【讨论】:

    • 非常感谢@rachid。我搜索了很多..到处都是我使用的格式。无论如何,它确实有帮助。
    猜你喜欢
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 2014-04-19
    • 2020-09-03
    • 2019-12-14
    • 1970-01-01
    相关资源
    最近更新 更多