python - Postgres Python 查询导入 pg 与导入 psycopg2

标签 python postgresql psycopg2

我正在编辑一个 python 脚本,我需要检查一个表是否存在。但是代码有效,因为我现在正在尝试检查表是否存在,所以我需要首先了解发生了什么。

目前代码有:

import pg
con = pg.connect(...)

和一堆调用:

con.query(...)

我在 SO 上找到了这个例子:Checking if a postgresql table exists under python (and probably Psycopg2) 但我不确定 psycopg2 是否与 pg 相同,而且我似乎找不到关于 pg 的任何文档,所以我不知道如果 import pg 可以像 psycopg2 那样做 con.exucute(...)

每次我搜索 pg 时,我都会得到 psycopg2 的文档。

有人知道这两者的区别吗? 我可以为 pg 使用 con.execute()con.cursor() 吗?

最佳答案

pg 指 PyGreSQL 驱动:

http://www.pygresql.org/

PyGreSQL is a Python module that interfaces to a PostgreSQL database. It embeds the PostgreSQL query library to allow easy use of the powerful PostgreSQL features from a Python script or application.

PyGreSQL consists of two parts: the “classic” PyGreSQL interface provided by the pg module and the newer DB-API 2.0 compliant interface provided by the pgdb module.

关于python - Postgres Python 查询导入 pg 与导入 psycopg2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45493595/

相关文章:

python - 在 Python (PostgreSQL) 中获取数据库结果中字段的表名

python - hl7apy 不显示具有多个 OBX 字段的数据

python - Django 或 mod_wsgi 在运行时会修改 sys.path 吗?

python - 为什么分配给多个目标(标识符/属性)会产生奇怪的结果?

sql - 如何将 float32 数组从 gorm 保存为 double

python - psycopg2 "select for update"

python - 检测原始数据的结尾

Ruby Sequel : Array returned by query is being returned as a String object, 不是数组对象

postgresql - Heroku 数据库恢复失败,提示有多个应用程序,但应用程序包含在恢复命令中

python - 连接时出现操作错误 - Psycopg2