API Reference for pg8000.
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
The DBAPI level supported, currently “2.0”.
This property is part of the DBAPI 2.0 specification.
Integer constant stating the level of thread safety the DBAPI interface supports. This DBAPI module supports sharing the module, connections, and cursors, resulting in a threadsafety value of 3.
This property is part of the DBAPI 2.0 specification.
String property stating the type of parameter marker formatting expected by the interface. This value defaults to “format”, in which parameters are marked in this format: “WHERE name=%s”.
This property is part of the DBAPI 2.0 specification.
As an extension to the DBAPI specification, this value is not constant; it can be changed to any of the following values:
- qmark
- Question mark style, eg. WHERE name=?
- numeric
- Numeric positional style, eg. WHERE name=:1
- named
- Named style, eg. WHERE name=:paramname
- format
- printf format codes, eg. WHERE name=%s
- pyformat
- Python format codes, eg. WHERE name=%(paramname)s
String type oid.
Numeric type oid
Timestamp type oid
ROWID type oid
Creates a connection to a PostgreSQL database.
This function is part of the DBAPI 2.0 specification; however, the arguments of the function are not defined by the specification.
Parameters: |
|
---|---|
Return type: | A Connection object. |
Constuct an object holding a date value.
This function is part of the DBAPI 2.0 specification.
Return type: | datetime.date |
---|
Construct an object holding a time value.
This function is part of the DBAPI 2.0 specification.
Return type: | datetime.time |
---|
Construct an object holding a timestamp value.
This function is part of the DBAPI 2.0 specification.
Return type: | datetime.datetime |
---|
Construct an object holding a date value from the given ticks value (number of seconds since the epoch).
This function is part of the DBAPI 2.0 specification.
Return type: | datetime.date |
---|
Construct an objet holding a time value from the given ticks value (number of seconds since the epoch).
This function is part of the DBAPI 2.0 specification.
Return type: | datetime.time |
---|
Construct an object holding a timestamp value from the given ticks value (number of seconds since the epoch).
This function is part of the DBAPI 2.0 specification.
Return type: | datetime.datetime |
---|
Construct an object holding binary data.
This function is part of the DBAPI 2.0 specification.
Return type: | pg8000.types.Bytea for Python 2, otherwise bytes |
---|
pg8000 uses the standard DBAPI 2.0 exception tree as “generic” exceptions. Generally, more specific exception types are raised; these specific exception types are derived from the generic exceptions.
Generic exception raised for important database warnings like data truncations. This exception is not currently used by pg8000.
This exception is part of the DBAPI 2.0 specification.
Generic exception that is the base exception of all other error exceptions.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised for errors that are related to the database interface rather than the database itself. For example, if the interface attempts to use an SSL connection but the server refuses, an InterfaceError will be raised.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised for errors that are related to the database. This exception is currently never raised by pg8000.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised for errors that are due to problems with the processed data. This exception is not currently raised by pg8000.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer. This exception is currently never raised by pg8000.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised when the relational integrity of the database is affected. This exception is not currently raised by pg8000.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised when the database encounters an internal error. This is currently only raised when unexpected state occurs in the pg8000 interface itself, and is typically the result of a interface bug.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised for programming errors. For example, this exception is raised if more parameter fields are in a query string than there are available parameters.
This exception is part of the DBAPI 2.0 specification.
Generic exception raised in case a method or database API was used which is not supported by the database.
This exception is part of the DBAPI 2.0 specification.
Exceptions that are subclassed from the standard DB-API 2.0 exceptions above.
Raised when attempting to transmit an array where the base type is not supported for binary data transfer by the interface.
Raised when attempting to transmit an array that doesn’t contain only a single type of object.
Raised when attempting to transmit an empty array. The type oid of an empty array cannot be determined, and so sending them is not permitted.
Raised when attempting to transmit an array that has inconsistent multi-dimension sizes.
A connection object is returned by the pg8000.connect() function. It represents a single physical connection to a PostgreSQL database.
A list of server-side notifications received by this database connection (via the LISTEN/NOTIFY PostgreSQL commands). Each list element is a two-element tuple containing the PostgreSQL backend PID that issued the notify, and the notification name.
PostgreSQL will only send notifications to a client between transactions. The contents of this property are generally only populated after a commit or rollback of the current transaction.
This list can be modified by a client application to clean out notifications as they are handled. However, inspecting or modifying this collection should only be done while holding the notifies_lock lock in order to guarantee thread-safety.
This attribute is not part of the DBAPI standard; it is a pg8000 extension.
New in version 1.07.
A threading.Lock object that should be held to read or modify the contents of the notifies list.
This attribute is not part of the DBAPI standard; it is a pg8000 extension.
New in version 1.07.
Following the DB-API specification, autocommit is off by default. It can be turned on by setting this boolean pg8000-specific autocommit property to True.
New in version 1.9.
All of the standard database exception types are accessible via connection instances.
This is a DBAPI 2.0 extension. Accessing any of these attributes will generate the warning DB-API extension connection.DatabaseError used.
Closes the database connection.
This function is part of the DBAPI 2.0 specification.
Commits the current database transaction.
This function is part of the DBAPI 2.0 specification.
Creates a Cursor object bound to this connection.
This function is part of the DBAPI 2.0 specification.
Rolls back the current database transaction.
This function is part of the DBAPI 2.0 specification.
Begins a TPC transaction with the given transaction ID xid.
This method should be called outside of a transaction (i.e. nothing may have executed since the last .commit() or .rollback()).
Furthermore, it is an error to call .commit() or .rollback() within the TPC transaction. A ProgrammingError is raised, if the application calls .commit() or .rollback() during an active TPC transaction.
This function is part of the DBAPI 2.0 specification.
When called with no arguments, .tpc_commit() commits a TPC transaction previously prepared with .tpc_prepare().
If .tpc_commit() is called prior to .tpc_prepare(), a single phase commit is performed. A transaction manager may choose to do this if only a single resource is participating in the global transaction.
When called with a transaction ID xid, the database commits the given transaction. If an invalid transaction ID is provided, a ProgrammingError will be raised. This form should be called outside of a transaction, and is intended for use in recovery.
On return, the TPC transaction is ended.
This function is part of the DBAPI 2.0 specification.
Performs the first phase of a transaction started with .tpc_begin(). A ProgrammingError is be raised if this method is called outside of a TPC transaction.
After calling .tpc_prepare(), no statements can be executed until .tpc_commit() or .tpc_rollback() have been called.
This function is part of the DBAPI 2.0 specification.
Returns a list of pending transaction IDs suitable for use with .tpc_commit(xid) or .tpc_rollback(xid).
This function is part of the DBAPI 2.0 specification.
When called with no arguments, .tpc_rollback() rolls back a TPC transaction. It may be called before or after .tpc_prepare().
When called with a transaction ID xid, it rolls back the given transaction. If an invalid transaction ID is provided, a ProgrammingError is raised. This form should be called outside of a transaction, and is intended for use in recovery.
On return, the TPC transaction is ended.
This function is part of the DBAPI 2.0 specification.
Create a Transaction IDs (only global_transaction_id is used in pg) format_id and branch_qualifier are not used in postgres global_transaction_id may be any string identifier supported by postgres returns a tuple (format_id, global_transaction_id, branch_qualifier)
A cursor object is returned by the cursor() method of a connection. It has the following attributes and methods:
This read/write attribute specifies the number of rows to fetch at a time with fetchmany(). It defaults to 1.
This read-only attribute contains a reference to the connection object (an instance of Connection) on which the cursor was created.
This attribute is part of a DBAPI 2.0 extension. Accessing this attribute will generate the following warning: DB-API extension cursor.connection used.
This read-only attribute contains the number of rows that the last execute() or executemany() method produced (for query statements like SELECT) or affected (for modification statements like UPDATE).
The value is -1 if:
This attribute is part of the DBAPI 2.0 specification.
This read-only attribute is a sequence of 7-item sequences. Each value contains information describing one result column. The 7 items returned for each column are (name, type_code, display_size, internal_size, precision, scale, null_ok). Only the first two values are provided by the current implementation.
This attribute is part of the DBAPI 2.0 specification.
Closes the cursor.
This method is part of the DBAPI 2.0 specification.
Executes a database operation. Parameters may be provided as a sequence, or as a mapping, depending upon the value of pg8000.paramstyle.
This method is part of the DBAPI 2.0 specification.
Parameters: |
|
---|
Prepare a database operation, and then execute it against all parameter sequences or mappings provided.
This method is part of the DBAPI 2.0 specification.
Parameters: |
|
---|
Fetches all remaining rows of a query result.
This method is part of the DBAPI 2.0 specification.
Returns: | A sequence, each entry of which is a sequence of field values making up a row. |
---|
Fetches the next set of rows of a query result.
This method is part of the DBAPI 2.0 specification.
Parameters: | size – The number of rows to fetch when called. If not provided, the arraysize attribute value is used instead. |
---|---|
Returns: | A sequence, each entry of which is a sequence of field values making up a row. If no more rows are available, an empty sequence will be returned. |
Fetch the next row of a query result set.
This method is part of the DBAPI 2.0 specification.
Returns: | A row as a sequence of field values, or None if no more rows are available. |
---|
This method is part of the DBAPI 2.0 specification, however, it is not implemented by pg8000.
This method is part of the DBAPI 2.0 specification, however, it is not implemented by pg8000.
Bytea is a str-derived class that is mapped to a PostgreSQL byte array. This class is only used in Python 2, the built-in bytes type is used in Python 3.
An Interval represents a measurement of time. In PostgreSQL, an interval is defined in the measure of months, days, and microseconds; as such, the pg8000 interval type represents the same information.
Note that values of the microseconds, days and months properties are independently measured and cannot be converted to each other. A month may be 28, 29, 30, or 31 days, and a day may occasionally be lengthened slightly by a leap second.
Measure of microseconds in the interval.
The microseconds value is constrained to fit into a signed 64-bit integer. Any attempt to set a value too large or too small will result in an OverflowError being raised.
Measure of days in the interval.
The days value is constrained to fit into a signed 32-bit integer. Any attempt to set a value too large or too small will result in an OverflowError being raised.
Measure of months in the interval.
The months value is constrained to fit into a signed 32-bit integer. Any attempt to set a value too large or too small will result in an OverflowError being raised.