This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the
current
version, or one of the other supported versions listed above instead.
Name
connect -- opens a connection to the
database server
Synopsis
connect([dbname], [host], [port], [opt], [tty], [user], [passwd])
Parameters
- dbname
-
Name of connected database (string/None).
- host
-
Name of the server host (string/None).
- port
-
Port used by the database server (integer/-1).
- opt
-
Options for the server (string/None).
- tty
-
File or tty for optional debug output from backend
(string/None).
- user
-
PostgreSQL user
(string/None).
- passwd
-
Password for user (string/None).
Return Type
- pgobject
-
If successful, an object handling a database
connection is returned.
Exceptions
- TypeError
-
Bad argument type, or too many arguments.
- SyntaxError
-
Duplicate argument definition.
- pg.error
-
Some error occurred during pg connection
definition.
(+ all exceptions relative to object allocation)
Description
This method opens a connection to a specified database on a
given PostgreSQL server. You can
use keywords here, as described in the Python tutorial. The names of the keywords
are the name of the parameters given in the syntax line. For a
precise description of the parameters, please refer to the
PostgreSQL user manual.
Examples
import pg
con1 = pg.connect('testdb', 'myhost', 5432, None, None, 'bob', None)
con2 = pg.connect(dbname='testdb', host='localhost', user='bob')