【问题标题】:equivalent connection for postgres and sqlitepostgres 和 sqlite 的等效连接
【发布时间】:2011-08-23 00:23:31
【问题描述】:

有没有一种等效的方式来连接到 postgres 数据库,就像 sqlite 使用 python 连接到数据库一样?

例如,在 sqlite 中,连接将由conn = sqlite3.connect(curruser.dbname) 定义。 postgres 的类似连接语法是什么?

【问题讨论】:

  • 您使用哪种编程语言?

标签: python sqlite postgresql


【解决方案1】:

然后您可以使用psycopg 连接器,连接语法将类似,只是您需要在连接字符串中指定更多信息:

conn_string = "host='localhost' dbname='my_database' user='postgres' password='secret'"
conn = psycopg2.connect(conn_string)

这里有一些例子:Using psycopg2 with PostgreSQL

【讨论】:

    猜你喜欢
    • 2022-01-24
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2013-06-29
    • 2014-05-28
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多