Chapter 9. PyGreSQL - Python Interface

Table of Contents
9.1. The pg Module
9.2. pg Module Functions
9.3. Connection object: pgobject
9.4. Database wrapper class: DB
9.5. Query result object: pgqueryobject
9.6. Large Object: pglarge
9.7. DB-API Interface

Author: Written by D'Arcy J.M. Cain (). Based heavily on code written by Pascal Andre . Copyright © 1995, Pascal Andre. Further modifications Copyright © 1997-2000 by D'Arcy J.M. Cain.

9.1. The pg Module

You may either choose to use the old mature interface provided by the pg module or otherwise the newer pgdb interface compliant with the DB-API 2.0 specification developed by the Python DB-SIG.

Here we describe only the older pg API. As long as PyGreSQL does not contain a description of the DB-API you should read about the API at http://www.python.org/topics/database/DatabaseAPI-2.0.html.

A tutorial-like introduction to the DB-API can be found at http://www2.linuxjournal.com/lj-issues/issue49/2605.html

The pg module defines three objects:

If you want to see a simple example of the use of some of these functions, see http://www.druid.net/rides where I have a link at the bottom to the actual Python code for the page.

9.1.1. Constants

Some constants are defined in the pg module dictionary. They are intended to be used as a parameters for methods calls. You should refer to the libpq description (Chapter 1) for more information about them. These constants are:

INV_READ, INV_WRITE, INV_ARCHIVE

large objects access modes, used by (pgobject.)locreate and (pglarge.)open.

SEEK_SET, SEEK_CUR, SEEK_END

positional flags, used by (pglarge.)seek.

version, __version__

constants that give the current version