pgdb â DB-API 2.0 compliant module for PyGreSQL.
| Use Case | Command | Description |
|---|---|---|
| đ Connect | pgdb.connect(dsn, user, password, host, database) | Open a database connection |
| đī¸ Cursor | connection.cursor() | Create a new cursor object |
| ⥠Execute | cursor.execute(query, params) | Execute a query with optional dictionary params |
| ⥠Execute Many | cursor.executemany(query, param_list) | Execute query with each param dict in list |
| âŦī¸ Fetch One | cursor.fetchone() | Fetch a single row as a list |
| âŦī¸ Fetch All | cursor.fetchall() | Fetch all remaining rows |
| âŦī¸ Fetch Many | cursor.fetchmany([size]) | Fetch up to size rows (default arraysize=1) |
| đ Row Count | cursor.rowcount | Number of rows in result set (after execute) |
| đ Description | cursor.description | List of column info tuples |
| â Commit | connection.commit() | Commit pending transaction |
| âŠī¸ Rollback | connection.rollback() | Roll back pending transaction |
| â Close Cursor | cursor.close() | Close the cursor |
| â Close Connection | connection.close() | Close the database connection |
(c) 1999, Pascal Andre <andre AT via.fr>. See package documentation for further copyright information.
Inline documentation is sparse. See DB-API 2.0 specification: http://www.python.org/peps/pep-0249.html
Basic usage:
pgdb.connect(connect_string) # open a connection
# connect_string = 'host:database:user:password:opt'
# All parts are optional. You may also pass host through
# password as keyword arguments. To pass a port,
# pass it in the host keyword parameter:
connection = pgdb.connect(host='localhost:5432')
cursor = connection.cursor() # open a cursor
cursor.execute(query[, params])
# Execute a query, binding params (a dictionary) if they are
# passed. The binding syntax is the same as the % operator
# for dictionaries, and no quoting is done.
cursor.executemany(query, list of params)
# Execute a query many times, binding each param dictionary
# from the list.
cursor.fetchone() # fetch one row, [value, value, ...]
cursor.fetchall() # fetch all rows, [[value, value, ...], ...]
cursor.fetchmany([size])
# returns size or cursor.arraysize number of rows,
# [[value, value, ...], ...] from result set.
# Default cursor.arraysize is 1.
cursor.description # returns information about the columns
# [(column_name, type_name, display_size,
# internal_size, precision, scale, null_ok), ...]
# Note that display_size, precision, scale and null_ok
# are not implemented.
cursor.rowcount # number of rows available in the result set
# Available after a call to execute.
connection.commit() # commit transaction
connection.rollback() # or rollback transaction
cursor.close() # close the cursor
connection.close() # close the connection
Exception hierarchy:
pg.Errorpg.DatabaseErrorpg.DataErrorpg.IntegrityErrorpg.NotSupportedErrorpg.OperationalErrorpg.ProgrammingErrorpg.InterfaceErrorpg.WarningBinaryHstoreTypeConnection, Cursor, Json, LiteralUuidConnection(cnx) â Connection object.
__enter__(self) â Enter runtime context for transactions (starts transaction in autocommit)__exit__(self, et, ev, tb) â Exit runtime context, ends transaction__init__(self, cnx) â Create a database connection objectclose(self) â Close the connectioncommit(self) â Commit pending transactioncursor(self) â Return a new cursor objectexecute(self, operation, params=None) â Shortcut to run an operation on an implicit cursorexecutemany(self, operation, param_seq) â Shortcut to run an operation against a sequence of parametersrollback(self) â Roll back pending transactionclosed â Check if connection is closed or brokenException attributes available on the connection:
DataError, DatabaseError, Error, IntegrityError, InterfaceError, InternalError, NotSupportedError, OperationalError, ProgrammingError, WarningCursor(dbcnx) â Cursor object.
__enter__(self) â Enter runtime context__exit__(self, et, ev, tb) â Exit runtime context__init__(self, dbcnx) â Create a cursor for the database connection__iter__(self) â Make cursor compatible with iteration protocol__next__(self) â Return next row (iteration protocol)build_row_factory(self) â Build a row factory for named tuples. Override to dynamically change row factories.callproc(self, procname, parameters=None) â Call a stored procedure. Output parameters currently not replaced.close(self) â Close the cursorcopy_from(self, stream, table, format=None, sep=None, null=None, size=None, columns=None) â Copy data from an input stream (file-like or iterable) to the specified table.copy_to(self, stream, table, format=None, sep=None, null=None, decode=None, columns=None) â Copy data from the specified table to an output stream. If stream is None, returns a generator. Use a select query instead of table name.execute(self, operation, parameters=None) â Prepare and execute a database operationexecutemany(self, operation, seq_of_parameters) â Prepare and execute against a parameter sequencefetchall(self) â Fetch all remaining rowsfetchmany(self, size=None, keep=False) â Fetch next set of rows. If keep=True, size becomes new arraysize.fetchone(self) â Fetch next rownext = __next__nextset() (not supported), setinputsizes(sizes) (not supported), setoutputsize(size, column=0) (not supported)row_factory(row) â Process rows before returning. Override statically or via build_row_factory.colnames, coltypes, descriptionBinary â Inherits from builtins.bytes. Construct an object capable of holding a binary (long) string value. Inherits all methods of bytes.
Hstore â Inherits from builtins.dict. Wrapper class for marking hstore values.
__str__(self) â Return str(self)Json(obj, encode=None) â Construct a wrapper for holding an object serializable to JSON.
__init__(self, obj, encode=None)__str__(self)Literal(sql) â Construct a wrapper for holding a literal SQL string.
__init__(self, sql)__pg_repr__ = __str__(self)__str__(self)Type(values) â Inherits from builtins.frozenset. Type class for PostgreSQL data types; types are dynamic so type names are used as internal codes.
__eq__(self, other)__ne__(self, other)__new__(cls, values)__hash__ = NoneUuid = uuid.UUID â Represents UUIDs per RFC 4122. Immutable, hashable, usable as dict keys.
Constructors: hex, bytes, bytes_le, fields, int. Read-only attributes: hex, int, bytes, bytes_le, fields, time_low, time_mid, time_hi_version, clock_seq_hi_variant, clock_seq_low, node, time, clock_seq, urn, variant, version, is_safe.
Base exception for all pgdb errors. Inherits from builtins.Exception.
__weakref__ descriptorMRO: DatabaseError â Error â Exception. Inherits all methods.
MRO: DataError â DatabaseError â Error â Exception. Inherits all methods.
MRO: IntegrityError â DatabaseError â Error â Exception. Inherits all methods.
MRO: InterfaceError â Error â Exception. Inherits all methods.
MRO: NotSupportedError â DatabaseError â Error â Exception. Inherits all methods.
MRO: OperationalError â DatabaseError â Error â Exception. Inherits all methods.
MRO: ProgrammingError â DatabaseError â Error â Exception. Inherits all methods.
MRO: Warning â Exception. Inherits all methods.
connect(dsn=None, user=None, password=None, host=None, database=None, **kwargs) â Connect to a database.Date(year, month, day) â Construct an object holding a date value.DateFromTicks(ticks) â Construct a date object from the given ticks value.Interval(days, hours=0, minutes=0, seconds=0, microseconds=0) â Construct a time interval value.Time(hour, minute=0, second=0, microsecond=0, tzinfo=None) â Construct a time value.TimeFromTicks(ticks) â Construct a time value from ticks.Timestamp(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None) â Construct a timestamp value.TimestampFromTicks(ticks) â Construct a timestamp from ticks.get_typecast(typ) â Get the global typecast function for the given database type(s).reset_typecast(typ=None) â Reset global typecasts to defaults. Connections cache casts; use con.type_cache.reset_typecast() to pick up changes.set_typecast(typ, cast) â Set a global typecast function for the given database type(s).ARRAY = <pgdb.ArrayType object>BINARY = Type({'bytea'})BOOL = Type({'bool'})DATE = Type({'date'})DATETIME = Type({'timestamptz', 'reltime', 'time', 'abstime', 'timesta...'})FLOAT = Type({'float8', 'float4'})HSTORE = Type({'hstore'})INTEGER = Type({'int2', 'int8', 'int4', 'serial'})INTERVAL = Type({'interval'})JSON = Type({'jsonb', 'json'})LONG = Type({'int8'})MONEY = Type({'money'})NUMBER = Type({'int4', 'float8', 'money', 'serial', 'int2', 'int8', 'n...'})NUMERIC = Type({'numeric'})RECORD = <pgdb.RecordType object>ROWID = Type({'oid'})SMALLINT = Type({'int2'})STRING = Type({'name', 'varchar', 'bpchar', 'text', 'char'})TIME = Type({'time', 'timetz'})TIMESTAMP = Type({'timestamptz', 'timestamp'})UUID = Type({'uuid'})__all__ = ['Connection', 'Cursor', 'Date', 'Time', 'Timestamp', 'DateF...']apilevel = '2.0'paramstyle = 'pyformat'threadsafety = 1version = '5.1.2'5.1.2
/usr/lib/python3/dist-packages/pgdb.py
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 19:11 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format