我正在编辑一个 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 驱动:
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/