简体   繁体   中英

Postgres Python Query import pg vs import psycopg2

I'm am working on editing a python script and I need to check if a table exists. The code works however since I am now trying to check if a table exists I need to first understand what is going on.

The code currently has:

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

and a bunch of calls to:

con.query(...)

I found this example on SO: Checking if a postgresql table exists under python (and probably Psycopg2) but I am unsure if psycopg2 is the same as pg and I can't seem to find any documentation on pg so I don't know if import pg can do con.exucute(...) simular to how psycopg2 can.

Everytime I search for pg I get documentation for psycopg2 .

Anyone know the differences between the two? Can I use con.execute() and con.cursor() for pg ?

pg refers to the PyGreSQL driver:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM