Postgres Python 查询 import pg vs import psycopg2

Postgres Python Query import pg vs import psycopg2

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

代码目前有:

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

和一堆电话:

con.query(...)

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

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

谁知道两者的区别? 我可以将 con.execute()con.cursor() 用于 pg 吗?

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.