- Fixed `~psycopg2.extras.RealDictCursor` when there are repeated columns
- Binary packages built with openssl 1.1.1b. Should fix concurrency problems
- Fixed `~psycopg2.extras.RealDictRow` modifiability (:ticket:`886`).
- Fixed "there's no async cursor" error polling a connection with no cursor
- Added `~psycopg2.errors` module. Every PostgreSQL error is converted into
a specific exception class (:ticket:`682`).
- Added `~psycopg2.extensions.encrypt_password()` function (:ticket:`576`).
- Added `~psycopg2.extensions.BYTES` adapter to manage databases with mixed
encodings on Python 3 (:ticket:`835`).
- Added `~psycopg2.extensions.Column.table_oid` and
`~psycopg2.extensions.Column.table_column` attributes on `cursor.description`
- Added `connection.info` object to retrieve various PostgreSQL connection
- Added `~connection.get_native_connection()` to expose the raw ``PGconn``
structure to C extensions via Capsule (:ticket:`782`).
- Added `~connection.pgconn_ptr` and `~cursor.pgresult_ptr` to expose raw
C structures to Python and interact with libpq via ctypes (:ticket:`782`).
- `~psycopg2.sql.Identifier` can represent qualified names in SQL composition
- Added `!ReplicationCursor`.\ `~psycopg2.extras.ReplicationCursor.wal_end`
- Added *fetch* parameter to `~psycopg2.extras.execute_values()` function
- `!str()` on `~psycopg2.extras.Range` produces a human-readable representation
- `~psycopg2.extras.DictCursor` and `~psycopg2.extras.RealDictCursor` rows
maintain columns order (:ticket:`177`).
- Added `~psycopg2.extensions.Diagnostics.severity_nonlocalized` attribute on
the `~psycopg2.extensions.Diagnostics` object (:ticket:`783`).
- More efficient `~psycopg2.extras.NamedTupleCursor` (:ticket:`838`).
- Fixed connections occasionally broken by the unrelated use of the
multiprocessing module (:ticket:`829`).
- Fixed async communication blocking if results are returned in different
chunks, e.g. with notices interspersed to the results (:ticket:`856`).
- Fixed adaptation of numeric subclasses such as `~enum.IntEnum`
- Dropped support for Python 2.6, 3.2, 3.3.
- Dropped `psycopg1` module.
- Dropped deprecated `!register_tstz_w_secs()` (was previously a no-op).
- Dropped deprecated `!PersistentConnectionPool`. This pool class was mostly
designed to interact with Zope. Use `!ZPsycopgDA.pool` instead.
- Binary packages no longer installed by default. The 'psycopg2-binary'
package must be used explicitly.
- Dropped `!PSYCOPG_DISPLAY_SIZE` build parameter.
- Dropped support for mxDateTime as the default date and time adapter.
mxDatetime support continues to be available as an alternative to Python's
- No longer use 2to3 during installation for Python 2 & 3 compatibility. All
source files are now compatible with Python 2 & 3 as is.
- The `!psycopg2.test` package is no longer installed by ``python setup.py
- Wheel package compiled against OpenSSL 1.0.2r and PostgreSQL 11.2 libpq.
- Cleanup of the cursor results assignment code, which might have solved
double free and inconsistencies in concurrent usage (:tickets:`346, 384`).
- Wheel package compiled against OpenSSL 1.0.2q.
- Fixed binary package broken on OS X 10.12 (:ticket:`807`).
- Wheel package compiled against PostgreSQL 11.1 libpq.
- Close named cursors if exist, even if `~cursor.execute()` wasn't called
- Fixed building on modern FreeBSD versions with Python 3.7 (:ticket:`755`).
- Fixed hang trying to :sql:`COPY` via `~cursor.execute()` in asynchronous
- Fixed adaptation of arrays of empty arrays (:ticket:`788`).
- Fixed segfault accessing the connection's `~connection.readonly` and
`~connection.deferrable` attributes repeatedly (:ticket:`790`).
- `~psycopg2.extras.execute_values()` accepts `~psycopg2.sql.Composable`
- `~psycopg2.errorcodes` map updated to PostgreSQL 11.
- Wheel package compiled against PostgreSQL 10.5 libpq and OpenSSL 1.0.2p.
- Allow non-ascii chars in namedtuple fields (regression introduced fixing
- Fixed adaptation of arrays of arrays of nulls (:ticket:`325`).
- Fixed building on Solaris 11 and derivatives such as SmartOS and illumos
- Maybe fixed building on MSYS2 (as reported in :ticket:`658`).
- Allow string subclasses in connection and other places (:ticket:`679`).
- Don't raise an exception closing an unused named cursor (:ticket:`716`).
- Wheel package compiled against PostgreSQL 10.4 libpq and OpenSSL 1.0.2o.
- Moving away from installing the wheel package by default.
Packages installed from wheel raise a warning on import. Added package
``psycopg2-binary`` to install from wheel instead (:ticket:`543`).
- Convert fields names into valid Python identifiers in
- Fixed Solaris 10 support (:ticket:`532`).
- `cursor.mogrify()` can be called on closed cursors (:ticket:`579`).
- Fixed setting session characteristics in corner cases on autocommit
- Fixed `~psycopg2.extras.MinTimeLoggingCursor` on Python 3 (:ticket:`609`).
- Fixed parsing of array of points as floats (:ticket:`613`).
- Fixed `~psycopg2.__libpq_version__` building with libpq >= 10.1
- Fixed `~cursor.rowcount` after `~cursor.executemany()` with :sql:`RETURNING`
- Fixed compatibility problem with pypy3 (:ticket:`649`).
- Wheel packages compiled against PostgreSQL 10.1 libpq and OpenSSL 1.0.2n.
- Wheel packages for Python 2.6 no more available (support dropped from
wheel building infrastructure).
- Wheel package compiled against PostgreSQL 10.0 libpq and OpenSSL 1.0.2l
- Dropped libresolv from wheel package to avoid incompatibility with
glibc 2.26 (wheels ticket 2).
- Restored default :sql:`timestamptz` typecasting to Python `!datetime`.
Regression introduced in Psycopg 2.7.2 (:ticket:`578`).
- Fixed inconsistent state in externally closed connections
(:tickets:`263, 311, 443`). Was fixed in 2.6.2 but not included in
2.7 by mistake.
- Fixed Python exceptions propagation in green callback (:ticket:`410`).
- Don't display the password in `connection.dsn` when the connection
string is specified as an URI (:ticket:`528`).
- Return objects with timezone parsing "infinity" :sql:`timestamptz`
- Dropped dependency on VC9 runtime on Windows binary packages
- Fixed segfault in `~connection.lobject()` when *mode*\=\ `!None`
- Fixed `~connection.lobject()` keyword argument *lobject_factory*
- Fixed `~psycopg2.extras.ReplicationCursor.consume_stream()`
*keepalive_interval* argument (:ticket:`547`).
- Maybe fixed random import error on Python 3.6 in multiprocess
- Fixed random `!SystemError` upon receiving abort signal (:ticket:`551`).
- Accept `~psycopg2.sql.Composable` objects in
- Parse intervals returned as microseconds from Redshift (:ticket:`558`).
- Added `~psycopg2.extras.Json` `!prepare()` method to consider connection
params when adapting (:ticket:`562`).
- `~psycopg2.errorcodes` map updated to PostgreSQL 10 beta 1.
- Ignore `!None` arguments passed to `~psycopg2.connect()` and
- OpenSSL upgraded from major version 0.9.8 to 1.0.2 in the Linux wheel
- Fixed build with libpq versions < 9.3 (:ticket:`520`).
- Added `~psycopg2.sql` module to generate SQL dynamically (:ticket:`308`).
- Added :ref:`replication-support` (:ticket:`322`). Main authors are
Oleksandr Shulgin and Craig Ringer, who deserve a huge thank you.
- Added `~psycopg2.extensions.parse_dsn()` and
`~psycopg2.extensions.make_dsn()` functions (:tickets:`321, 363`).
`~psycopg2.connect()` now can take both *dsn* and keyword arguments, merging
- Added `~psycopg2.__libpq_version__` and
`~psycopg2.extensions.libpq_version()` to inspect the version of the
``libpq`` library the module was compiled/loaded with
- The attributes `~connection.notices` and `~connection.notifies` can be
customized replacing them with any object exposing an `!append()` method
- Adapt network types to `ipaddress` objects when available. When not
enabled, convert arrays of network types to lists by default. The old `!Inet`
adapter is deprecated (:tickets:`317, 343, 387`).
- Added `~psycopg2.extensions.quote_ident()` function (:ticket:`359`).
- Added `~connection.get_dsn_parameters()` connection method (:ticket:`364`).
- `~cursor.callproc()` now accepts a dictionary of parameters (:ticket:`381`).
- Give precedence to `!__conform__()` over superclasses to choose an object
- Using Python C API decoding functions and codecs caching for faster
unicode encoding/decoding (:ticket:`473`).
- `~cursor.executemany()` slowness addressed by
`~psycopg2.extras.execute_batch()` and `~psycopg2.extras.execute_values()`
- Added ``async_`` as an alias for ``async`` to support Python 3.7 where
``async`` will become a keyword (:ticket:`495`).
- Unless in autocommit, do not use :sql:`default_transaction_*` settings to
control the session characteristics as it may create problems with external
connection pools such as pgbouncer; use :sql:`BEGIN` options instead
- `~connection.isolation_level` is now writable and entirely separated from
`~connection.autocommit`; added `~connection.readonly`,
`~connection.deferrable` writable attributes.
- Throw an exception trying to pass ``NULL`` chars as parameters
- Fixed error caused by missing decoding `~psycopg2.extras.LoggingConnection`
- Fixed integer overflow in :sql:`interval` seconds (:ticket:`512`).
- Make `~psycopg2.extras.Range` objects picklable (:ticket:`462`).
- Fixed version parsing and building with PostgreSQL 10 (:ticket:`489`).
- Dropped support for Python 2.5 and 3.1.
- Dropped support for client library older than PostgreSQL 9.1 (but older
server versions are still supported).
- `~connection.isolation_level` doesn't read from the database but will return
`~psycopg2.extensions.ISOLATION_LEVEL_DEFAULT` if no value was set on the
- Empty arrays no more converted into lists if they don't have a type attached
- Fixed inconsistent state in externally closed connections
(:tickets:`263, 311, 443`).
- Report the server response status on errors (such as :ticket:`281`).
- Raise `!NotSupportedError` on unhandled server response status
- Allow overriding string adapter encoding with no connection (:ticket:`331`).
- The `~psycopg2.extras.wait_select` callback allows interrupting a
long-running query in an interactive shell using :kbd:`Ctrl-C`
- Fixed `!PersistentConnectionPool` on Python 3 (:ticket:`348`).
- Fixed segfault on `repr()` of an unitialized connection (:ticket:`361`).
- Allow adapting bytes using `~psycopg2.extensions.QuotedString` on Python 3
- Added support for setuptools/wheel (:ticket:`370`).
- Fix build on Windows with Python 3.5, VS 2015 (:ticket:`380`).
- Fixed `!errorcodes.lookup` initialization thread-safety (:ticket:`382`).
- Fixed `!read()` exception propagation in copy_from (:ticket:`412`).
- Fixed possible NULL TZ decref (:ticket:`424`).
- `~psycopg2.errorcodes` map updated to PostgreSQL 9.5.
- Lists consisting of only `None` are escaped correctly (:ticket:`285`).
- Fixed deadlock in multithread programs using OpenSSL (:ticket:`290`).
- Correctly unlock the connection after error in flush (:ticket:`294`).
- Fixed `!MinTimeLoggingCursor.callproc()` (:ticket:`309`).
- Added support for MSVC 2015 compiler (:ticket:`350`).
- Added support for large objects larger than 2GB. Many thanks to Blake Rouse
and the MAAS Team for the feature development.
- Python `time` objects with a tzinfo specified and PostgreSQL :sql:`timetz`
data are converted into each other (:ticket:`272`).
- Json adapter's `!str()` returns the adapted content instead of the `!repr()`
- Named cursors used as context manager don't swallow the exception on exit
- `cursor.description` can be pickled (:ticket:`265`).
- Propagate read error messages in COPY FROM (:ticket:`270`).
- PostgreSQL time 24:00 is converted to Python 00:00 (:ticket:`278`).
- Added :sql:`jsonb` support for PostgreSQL 9.4 (:ticket:`226`).
- Fixed segfault if COPY statements are passed to `~cursor.execute()` instead
of using the proper methods (:ticket:`219`).
- Force conversion of pool arguments to integer to avoid potentially unbounded
- Cursors :sql:`WITH HOLD` don't begin a new transaction upon move/fetch/close
- Cursors :sql:`WITH HOLD` can be used in autocommit (:ticket:`229`).
- `~cursor.callproc()` doesn't silently ignore an argument without a length.
- Fixed memory leak with large objects (:ticket:`256`).
- Make sure the internal ``_psycopg.so`` module can be imported stand-alone (to
allow modules juggling such as the one described in :ticket:`201`).
- Work around `pip issue 1630 <https://github.com/pypa/pip/issues/1630>`__
making installation via ``pip -e git+url`` impossible (:ticket:`18`).
- Copy operations correctly set the `cursor.rowcount` attribute
- It is now possible to call `get_transaction_status()` on closed connections.
- Fixed unsafe access to object names causing assertion failures in
Python 3 debug builds (:ticket:`188`).
- Mark the connection closed if found broken on `poll()` (from :ticket:`192`
- Fixed handling of dsn and closed attributes in connection subclasses
failing to connect (from :ticket:`192` discussion).
- Added arbitrary but stable order to `Range` objects, thanks to
Chris Withers (:ticket:`193`).
- Avoid blocking async connections on connect (:ticket:`194`). Thanks to
Adam Petrovich for the bug report and diagnosis.
- Don't segfault using poorly defined cursor subclasses which forgot to call
the superclass init (:ticket:`195`).
- Mark the connection closed when a Socket connection is broken, as it
happens for TCP connections instead (:ticket:`196`).
- Fixed overflow opening a lobject with an oid not fitting in a signed int
- Fixed handling of explicit default ``cursor_factory=None`` in
- Fixed possible segfault in named cursors creation.
- Fixed debug build on Windows, thanks to James Emerton.
- Fixed segfault pickling the exception raised on connection error
- Meaningful connection errors report a meaningful message, thanks to
Alexey Borzenkov (:ticket:`173`).
- Manually creating `lobject` with the wrong parameter doesn't segfault
- Fixed build on Solaris 10 and 11 where the round() function is already
- Fixed comparison of `Range` with non-range objects (:ticket:`164`).
Thanks to Chris Withers for the patch.
- Fixed double-free on connection dealloc (:ticket:`166`). Thanks to
Gangadharan S.A. for the report and fix suggestion.
- Added :ref:`JSON adaptation <adapt-json>`.
- Added :ref:`support for PostgreSQL 9.2 range types <adapt-range>`.
- `connection` and `cursor` objects can be used in ``with`` statements
as context managers as specified by recent |DBAPI|_ extension.
- Added `~psycopg2.extensions.Diagnostics` object to get extended info
from a database error. Many thanks to Matthew Woodcraft for the
- Added `connection.cursor_factory` attribute to customize the default
object returned by `~connection.cursor()`.
- Added support for backward scrollable cursors. Thanks to Jon Nelson
for the initial patch (:ticket:`108`).
- Added a simple way to :ref:`customize casting of composite types
<adapt-composite>` into Python objects other than namedtuples.
Many thanks to Ronan Dunklau and Tobias Oberstein for the feature
- `connection.reset()` implemented using :sql:`DISCARD ALL` on server
versions supporting it.
- Properly cleanup memory of broken connections (:ticket:`148`).
- Fixed bad interaction of ``setup.py`` with other dependencies in
Distribute projects on Python 3 (:ticket:`153`).
- Added support for Python 3.3.
- Dropped support for Python 2.4. Please use Psycopg 2.4.x if you need it.
- `~psycopg2.errorcodes` map updated to PostgreSQL 9.2.
- Dropped Zope adapter from source repository. ZPsycopgDA now has its own
project at <https://github.com/psycopg/ZPsycopgDA>.
- Fixed 'cursor()' arguments propagation in connection subclasses
and overriding of the 'cursor_factory' argument. Thanks to
Corry Haines for the report and the initial patch (:ticket:`105`).
- Dropped GIL release during string adaptation around a function call
invoking a Python API function, which could cause interpreter crash.
Thanks to Manu Cupcic for the report (:ticket:`110`).
- Close a green connection if there is an error in the callback.
Maybe a harsh solution but it leaves the program responsive
- 'register_hstore()', 'register_composite()', 'tpc_recover()' work with
RealDictConnection and Cursor (:ticket:`114`).
- Fixed broken pool for Zope and connections re-init across ZSQL methods
in the same request (:tickets:`123, 125, 142`).
- connect() raises an exception instead of swallowing keyword arguments
when a connection string is specified as well (:ticket:`131`).
- Discard any result produced by 'executemany()' (:ticket:`133`).
- Fixed pickling of FixedOffsetTimezone objects (:ticket:`135`).
- Release the GIL around PQgetResult calls after COPY (:ticket:`140`).
- Fixed empty strings handling in composite caster (:ticket:`141`).
- Fixed pickling of DictRow and RealDictRow objects.
- The close() methods on connections and cursors don't raise exceptions
if called on already closed objects.
- Fixed fetchmany() with no argument in cursor subclasses
- Use lo_creat() instead of lo_create() when possible for better
interaction with pgpool-II (:ticket:`88`).
- Error and its subclasses are picklable, useful for multiprocessing
- Better efficiency and formatting of timezone offset objects thanks
to Menno Smits (:tickets:`94, 95`).
- Fixed 'rownumber' during iteration on cursor subclasses.
Regression introduced in 2.4.4 (:ticket:`100`).
- Added support for 'inet' arrays.
- Fixed 'commit()' concurrency problem (:ticket:`103`).
- Codebase cleaned up using the GCC Python plugin's static analysis
tool, which has revealed several unchecked return values, possible
NULL dereferences, reference counting problems. Many thanks to David
Malcolm for the useful tool and the assistance provided using it.
- 'register_composite()' also works with the types implicitly defined
after a table row, not only with the ones created by 'CREATE TYPE'.
- Values for the isolation level symbolic constants restored to what
they were before release 2.4.2 to avoid breaking apps using the
values instead of the constants.
- Named DictCursor/RealDictCursor honour itersize (:ticket:`80`).
- Fixed rollback on error on Zope (:ticket:`73`).
- Raise 'DatabaseError' instead of 'Error' with empty libpq errors,
consistently with other disconnection-related errors: regression
introduced in release 2.4.1 (:ticket:`82`).
- connect() supports all the keyword arguments supported by the
- Added 'new_array_type()' function for easy creation of array
- Added support for arrays of hstores and composite types (:ticket:`66`).
- Fixed segfault in case of transaction started with connection lost
(and possibly other events).
- Fixed adaptation of Decimal type in sub-interpreters, such as in
certain mod_wsgi configurations (:ticket:`52`).
- Rollback connections in transaction or in error before putting them
back into a pool. Also discard broken connections (:ticket:`62`).
- Lazy import of the slow uuid module, thanks to Marko Kreen.
- Fixed NamedTupleCursor.executemany() (:ticket:`65`).
- Fixed --static-libpq setup option (:ticket:`64`).
- Fixed interaction between RealDictCursor and named cursors
- Dropped limit on the columns length in COPY operations (:ticket:`68`).
- Fixed reference leak with arguments referenced more than once
in queries (:ticket:`81`).
- Fixed typecasting of arrays containing consecutive backslashes.
- 'errorcodes' map updated to PostgreSQL 9.1.
- Added 'set_session()' method and 'autocommit' property to the
connection. Added support for read-only sessions and, for PostgreSQL
9.1, for the "repeatable read" isolation level and the "deferrable"
- Psycopg doesn't execute queries at connection time to find the
default isolation level.
- Fixed bug with multithread code potentially causing loss of sync
with the server communication or lock of the client (:ticket:`55`).
- Don't fail import if mx.DateTime module can't be found, even if its
support was built (:ticket:`53`).
- Fixed escape for negative numbers prefixed by minus operator
- Fixed refcount issue during copy. Reported and fixed by Dave
Malcolm (:ticket:`58`, Red Hat Bug 711095).
- Trying to execute concurrent operations on the same connection
through concurrent green thread results in an error instead of a
- Fixed detection of pg_config on Window. Report and fix, plus some
long needed setup.py cleanup by Steve Lacy: thanks!
- Use own parser for bytea output, not requiring anymore the libpq 9.0
to parse the hex format.
- Don't fail connection if the client encoding is a non-normalized
variant. Issue reported by Peter Eisentraut.
- Correctly detect an empty query sent to the backend (:ticket:`46`).
- Fixed a SystemError clobbering libpq errors raised without SQLSTATE.
Bug vivisectioned by Eric Snow.
- Fixed interaction between NamedTuple and server-side cursors.
- Allow to specify --static-libpq on setup.py command line instead of
just in 'setup.cfg'. Patch provided by Matthew Ryan (:ticket:`48`).
New features and changes:
- Added support for Python 3.1 and 3.2. The conversion has also
brought several improvements:
- Added 'b' and 't' mode to large objects: write can deal with both
bytes strings and unicode; read can return either bytes strings
or decoded unicode.
- COPY sends Unicode data to files implementing 'io.TextIOBase'.
- Improved PostgreSQL-Python encodings mapping.
- Added a few missing encodings: EUC_CN, EUC_JIS_2004, ISO885910,
ISO885916, LATIN10, SHIFT_JIS_2004.
- Dropped repeated dictionary lookups with unicode query/parameters.
- Improvements to the named cursors:
- More efficient iteration on named cursors, fetching 'itersize'
records at time from the backend.
- The named cursors name can be an invalid identifier.
- Improvements in data handling:
- Added 'register_composite()' function to cast PostgreSQL
composite types into Python tuples/namedtuples.
- Adapt types 'bytearray' (from Python 2.6), 'memoryview' (from
Python 2.7) and other objects implementing the "Revised Buffer
Protocol" to 'bytea' data type.
- The 'hstore' adapter can work even when the data type is not
installed in the 'public' namespace.
- Raise a clean exception instead of returning bad data when
receiving bytea in 'hex' format and the client libpq can't parse
- Empty lists correctly roundtrip Python -> PostgreSQL -> Python.
- Other changes:
- 'cursor.description' is provided as named tuples if available.
- The build script refuses to guess values if 'pg_config' is not
- Connections and cursors are weakly referenceable.
- Fixed adaptation of None in composite types (:ticket:`26`). Bug
report by Karsten Hilbert.
- Fixed several reference leaks in less common code paths.
- Fixed segfault when a large object is closed and its connection no
- Added missing icon to ZPsycopgDA package, not available in Zope
2.12.9 (:ticket:`30`). Bug report and patch by Pumukel.
- Fixed conversion of negative infinity (:ticket:`40`). Bug report and
patch by Marti Raudsepp.
- Fixed segfault with middleware not passing DateStyle to the client
(:ticket:`24`). Bug report and patch by Marti Raudsepp.
- Fixed build problem on CentOS 5.5 x86_64 (:ticket:`23`).
psycopg 2.3 aims to expose some new features introduced in PostgreSQL 9.0.
Main new features:
- `dict` to `hstore` adapter and `hstore` to `dict` typecaster, using both
9.0 and pre-9.0 syntax.
- Two-phase commit protocol support as per DBAPI specification.
- Support for payload in notifications received from the backend.
- `namedtuple`-returning cursor.
- Query execution cancel.
Other features and changes:
- Dropped support for protocol 2: Psycopg 2.3 can only connect to PostgreSQL
servers with version at least 7.4.
- Don't issue a query at every connection to detect the client encoding
and to set the datestyle to ISO if it is already compatible with what
- `mogrify()` now supports unicode queries.
- Subclasses of a type that can be adapted are adapted as the superclass.
- `errorcodes` knows a couple of new codes introduced in PostgreSQL 9.0.
- Dropped deprecated Psycopg "own quoting".
- Never issue a ROLLBACK on close/GC. This behaviour was introduced as a bug
in release 2.2, but trying to send a command while being destroyed has been
considered not safe.
- Fixed use of `PQfreemem` instead of `free` in binary typecaster.
- Fixed access to freed memory in `conn_get_isolation_level()`.
- Fixed crash during Decimal adaptation with a few 2.5.x Python versions
- Fixed notices order (:ticket:`9`).
- the call to logging.basicConfig() in pool.py has been dropped: it was
messing with some projects using logging (and a library should not
initialize the logging system anyway.)
- psycopg now correctly handles time zones with seconds in the UTC offset.
The old register_tstz_w_secs() function is deprecated and will raise a
warning if called.
- Exceptions raised by the column iterator are propagated.
- Exceptions raised by executemany() iterators are propagated.
- psycopg now builds again on MS Windows.
This is the first release of the new 2.2 series, supporting not just one but
two different ways of executing asynchronous queries, thanks to Jan and Daniele
(with a little help from me and others, but they did 99% of the work so they
deserve their names here in the news.)
psycopg now supports both classic select() loops and "green" coroutine
libraries. It is all in the documentation, so just point your browser to
Other new features:
- truncate() method for lobjects.
- COPY functions are now a little bit faster.
- All builtin PostgreSQL to Python typecasters are now available from the
- Notifications from the backend are now available right after the execute()
call (before client code needed to call isbusy() to ensure NOTIFY
- Better timezone support.
- Lots of documentation updates.
- Fixed some gc/refcounting problems.
- Fixed reference leak in NOTIFY reception.
- Fixed problem with PostgreSQL not casting string literals to the correct
types in some situations: psycopg now add an explicit cast to dates, times
and bytea representations.
- Fixed TimestampFromTicks() and TimeFromTicks() for seconds >= 59.5.
- Fixed spurious exception raised when calling C typecasters from Python
- Support for adapting tuples to PostgreSQL arrays is now enabled by
default and does not require importing psycopg2.extensions anymore.
- "can't adapt" error message now includes full type information.
- Thank to Daniele Varrazzo (piro) psycopg2's source package now includes
full documentation in HTML and plain text format.
- No loss of precision when using floats anymore.
- decimal.Decimal "nan" and "infinity" correctly converted to PostgreSQL
numeric NaN values (note that PostgreSQL numeric type does not support
infinity but just NaNs.)
- psycopg2.extensions now includes Binary.
It seems we're good citizens of the free software ecosystem and that big
big big companies and people ranting on the pgsql-hackers mailing list
we'll now not dislike us. *g* (See LICENSE file for the details.)
- Support for UUID arrays.
- It is now possible to build psycopg linking to a static libpq
- Fixed a deadlock related to using the same connection with
multiple cursors from different threads.
- Builds again with MSVC.
- The connection object now has a reset() method that can be used to
reset the connection to its default state.
- copy_to() and copy_from() now accept a much larger number of columns.
- Fixed PostgreSQL version detection.
- Fixed ZPsycopgDA version check.
- Fixed regression in ZPsycopgDA that made it behave wrongly when
receiving serialization errors: now the query is re-issued as it
should be by propagating the correct exception to Zope.
- Writing "large" large objects should now work.
- DictRow and RealDictRow now use less memory. If you inherit on them
remember to set __slots__ for your new attributes or be prepare to
go back to old memory usage.
- Fixed exception in setup.py.
- More robust detection of PostgreSQL development versions.
- Fixed exception in RealDictCursor, introduced in 2.0.10.
- A specialized type-caster that can parse time zones with seconds is
now available. Note that after enabling it (see extras.py) "wrong"
time zones will be parsed without raising an exception but the
result will be rounded.
- DictCursor can be used as a named cursor.
- DictRow now implements more dict methods.
- The connection object now expose PostgreSQL server version as the
.server_version attribute and the protocol version used as
- The connection object has a .get_parameter_status() methods that
can be used to obtain useful information from the server.
- None is now correctly always adapted to NULL.
- Two double memory free errors provoked by multithreading and
garbage collection are now fixed.
- Fixed usage of internal Python code in the notice processor; this
should fix segfaults when receiving a lot of notices in
- Should build again on MSVC and Solaris.
- Should build with development versions of PostgreSQL (ones with
-devel version string.)
- Fixed some tests that failed even when psycopg was right.
- COPY TO/COPY FROM queries now can be of any size and psycopg will
correctly quote separators.
- float values Inf and NaN are now correctly handled and can
round-trip to the database.
- executemany() now return the numer of total INSERTed or UPDATEd
rows. Note that, as it has always been, executemany() should not
be used to execute multiple SELECT statements and while it will
execute the statements without any problem, it will return the
- copy_from() and copy_to() can now use quoted separators.
- "import psycopg2.extras" to get UUID support.
- register_type() now works on connection and cursor subclasses.
- fixed a memory leak when using lobjects.
- The connection object now has a get_backend_pid() method that
returns the current PostgreSQL connection backend process PID.
- The PostgreSQL large object API has been exposed through the
- Some fixes to ZPsycopgDA have been merged from the Debian package.
- A memory leak was fixed in Cursor.executemany().
- A double free was fixed in pq_complete_error(), that caused crashes
under some error conditions.
Improved error handling:
- All instances of psycopg2.Error subclasses now have pgerror,
pgcode and cursor attributes. They will be set to None if no
value is available.
- Exception classes are now chosen based on the SQLSTATE value from
the result. (184)
- The commit() and rollback() methods now set the pgerror and pgcode
attributes on exceptions. (152)
- errors from commit() and rollback() are no longer considered
- If a disconnect is detected during execute(), an exception will be
raised at that point rather than resulting in "ProgrammingError:
no results to fetch" later on. (186)
Better PostgreSQL compatibility:
- If the server uses standard_conforming_strings, perform
- BC dates are now handled if psycopg is compiled with mxDateTime
support. If using datetime, an appropriate ValueError is
Other bug fixes:
- If multiple sub-interpreters are in use, do not share the Decimal
type between them. (192)
- Buffer objects obtained from psycopg are now accepted by psycopg
too, without segfaulting. (209)
- A few small changes were made to improve DB-API compatibility.
All the dbapi20 tests now pass.
- The PSYCOPG_DISPLAY_SIZE option is now off by default. This means
that display size will always be set to "None" in
cursor.description. Calculating the display size was expensive,
and infrequently used so this should improve performance.
- New QueryCanceledError and TransactionRollbackError exceptions
have been added to the psycopg2.extensions module. They can be
used to detect statement timeouts and deadlocks respectively.
- Cursor objects now have a "closed" attribute. (164)
- If psycopg has been built with debug support, it is now necessary
to set the PSYCOPG_DEBUG environment variable to turn on debug
Better support for PostgreSQL, Python and win32:
- full support for PostgreSQL 8.2, including NULLs in arrays
- support for almost all existing PostgreSQL encodings
- full list of PostgreSQL error codes available by importing the
- full support for Python 2.5 and 64 bit architectures
- better build support on win32 platform
Support for per-connection type-casters (used by ZPsycopgDA too, this
fixes a long standing bug that made different connections use a random
set of date/time type-casters instead of the configured one.)
Better management of times and dates both from Python and in Zope.
copy_to and copy_from now take an extra "columns" parameter.
Python tuples are now adapted to SQL sequences that can be used with
the "IN" operator by default if the psycopg2.extensions module is
imported (i.e., the SQL_IN adapter was moved from extras to extensions.)
Fixed some small buglets and build glitches:
- removed double mutex destroy
- removed all non-constant initializers
- fixed PyObject_HEAD declarations to avoid memory corruption
on 64 bit architectures
- fixed several Python API calls to work on 64 bit architectures
- applied compatibility macros from PEP 353
- now using more than one argument format raise an error instead of
* Now it really, really builds on MSVC and older gcc versions.
* Fixed various buglets such as:
- segfault when passing an empty string to Binary()
- segfault on null queries
- segfault and bad keyword naming in .executemany()
- OperationalError in connection objects was always None
* Various changes to ZPsycopgDA to make it more zope2.9-ish.
* connect() now accept both integers and strings as port parameter
* Fixed float conversion bug introduced in 2.0.3.
* Fixed various buglets and a memory leak (see ChangeLog for details)
* Fixed a bug in array typecasting that sometimes made psycopg forget about
the last element in the array.
* Fixed some minor buglets in string memory allocations.
* Builds again with compilers different from gcc (warning about PostgreSQL
version is issued only if __GCC__ is defined.)
* ZPsycopgDA now actually loads.
* Fixed handle leak on win32.
* If available the new "safe" encoding functions of libpq are used.
* django and tinyerp people, please switch to psycopg 2 _without_
using a psycopg 1 compatibility layer (this release was anticipated
so that you all stop grumbling about psycopg 2 is still in beta.. :)
What's new in psycopg 2.0 beta 7
* Ironed out last problems with times and date (should be quite solid now.)
* Fixed problems with some arrays.
* Slightly better ZPsycopgDA (no more double connection objects in the menu
and other minor fixes.)
* ProgrammingError exceptions now have three extra attributes: .cursor
(it is possible to access the query that caused the exception using
error.cursor.query), .pgerror and .pgcode (PostgreSQL original error
text and code.)
* The build system uses pg_config when available.
* Documentation in the doc/ directory! (With many kudos to piro.)
What's new in psycopg 2.0 beta 6
* Support for named cursors.
* Safer parsing of time intervals.
* Better parsing of times and dates, no more locale problems.
* Should now play well with py2exe and similar tools.
* The "decimal" module is now used if available under Python 2.3.
What's new in psycopg 2.0 beta 5
* Fixed all known bugs.
* The initial isolation level is now read from the server and
.set_isolation_level() now takes values defined in psycopg2.extensions.
* .callproc() implemented as a SELECT of the given procedure.
* Better docstrings for a few functions/methods.
* Some time-related functions like psycopg2.TimeFromTicks() now take the
local timezone into account. Also a tzinfo object (as per datetime module
specifications) can be passed to the psycopg2.Time and psycopg2.Datetime
* All classes have been renamed to exist in the psycopg2._psycopg module,
to fix problems with automatic documentation generators like epydoc.
* NOTIFY is correctly trapped.
What's new in psycopg 2.0 beta 4
* psycopg module is now named psycopg2.
* No more segfaults when a UNICODE query can't be converted to the
* No more segfaults on empty queries.
* psycopg2.connect() now takes an integer for the port keyword parameter.
* "python setup.py bdist_rpm" now works.
* Fixed lots of small bugs, see ChangeLog for details.
What's new in psycopg 2.0 beta 3
* ZPsycopgDA now works (except table browsing.)
* psycopg build again on Python 2.2.
What's new in psycopg 2.0 beta 2
* Fixed ZPsycopgDA version check (ZPsycopgDA can now be imported in
* psycopg.extras.DictRow works even after a new query on the generating
* Better setup.py for win32 (should build with MSCV or mingw.)
* Generic fixed and memory leaks plugs.
What's new in psycopg 2.0 beta 1
* Officially in beta (i.e., no new features will be added.)
* Array support: list objects can be passed as bound variables and are
correctly returned for array columns.
* Added the psycopg.psycopg1 compatibility module (if you want instant
psycopg 1 compatibility just "from psycopg import psycopg1 as psycopg".)
* Complete support for BYTEA columns and buffer objects.
* Added error codes to error messages.
* The AsIs adapter is now exported by default (also Decimal objects are
adapted using the AsIs adapter (when str() is called on them they
already format themselves using the right precision and scale.)
* The connect() function now takes "connection_factory" instead of
"factory" as keyword argument.
* New setup.py code to build on win32 using mingw and better error
messages on missing datetime headers,
* Internal changes that allow much better user-defined type casters.
* A lot of bugfixes (binary, datetime, 64 bit arches, GIL, .executemany())
* Added missing .executemany() method.
* Optimized type cast from PostgreSQL to Python (psycopg should be even
faster than before.)
* .rowcount should be ok and in sync with psycopg 1.
* Implemented the new COPY FROM/COPY TO code when connection to the
backend using libpq protocol 3 (this also removes all asprintf calls:
build on win32 works again.) A protocol 3-enabled psycopg *can*
connect to an old protocol 2 database and will detect it and use the
* getquoted() called for real by the mogrification code.
* 'cursor' argument in .cursor() connection method renamed to
* changed 'tuple_factory' cursor attribute name to 'row_factory'.
* the .cursor attribute is gone and connections and cursors are properly
* fixes to the async core.
* The adapt() function now fully supports the adaptation protocol
described in PEP 246. Note that the adapters registry now is indexed
by (type, protocol) and not by type alone. Change your adapters
* More configuration options moved from setup.py to setup.cfg.
* Fixed two memory leaks: one in cursor deallocation and one in row
fetching (.fetchXXX() methods.)
* Added simple pooling code (psycopg.pool module).
* Added DECIMAL typecaster to convert postgresql DECIMAL and NUMERIC
types (i.e, all types with an OID of NUMERICOID.) Note that the
DECIMAL typecaster does not set scale and precision on the created
objects but uses Python defaults.
* ZPsycopgDA back in and working using the new pooling code.
* Isn't that enough? :)
* added support for UNICODE queries.
* added UNICODE typecaster; to activate it just do::
Note that the UNICODE typecaster override the STRING one, so it is
not activated by default.
* cursors now really support the iterator protocol.
* solved the rounding errors in time conversions.
* now cursors support .fileno() and .isready() methods, to be used in
* .copy_from() and .copy_in() methods are back in (still using the old
protocol, will be updated to use new one in next release.)
* fixed memory corruption bug reported on win32 platform.
* added support for tuple factories in cursor objects (removed factory
argument in favor of a .tuple_factory attribute on the cursor object);
see the new module psycopg.extras for a cursor (DictCursor) that
return rows as objects that support indexing both by position and
* added support for tzinfo objects in datetime.timestamp objects: the
PostgreSQL type "timestamp with time zone" is converted to
datetime.timestamp with a FixedOffsetTimezone initialized as necessary.
* sslmode parameter from 1.1.x
* various datetime conversion improvements.
* now psycopg should compile without mx or without native datetime
(not both, obviously.)
* included various win32/MSVC fixes (pthread.h changes, winsock2
library, include path in setup.py, etc.)
* ported interval fixes from 1.1.14/1.1.15.
* the last query executed by a cursor is now available in the
* conversion of unicode strings to backend encoding now uses a table
(that still need to be filled.)
* cursors now have a .mogrify() method that return the query string
instead of executing it.
* connection objects now have a .dsn read-only attribute that holds the
* moved psycopg C module to _psycopg and made psycopg a python module:
this allows for a neat separation of DBAPI-2.0 functionality and psycopg
extensions; the psycopg namespace will be also used to provide
python-only extensions (like the pooling code, some ZPsycopgDA support
functions and the like.)
* initial working support for unicode bound variables: UTF-8 and latin-1
backend encodings are natively supported (and the encoding.py example even
* added .set_client_encoding() method on the connection object.
* added examples: encoding.py, binary.py, lastrowid.py.
* better typecasting:
- DateTimeDelta used for postgresql TIME (merge from 1.1)
- BYTEA now is converted to a real buffer object, not to a string
* buffer objects are now adapted into Binary objects automatically.
* ported scroll method from 1.1 (DBAPI-2.0 extension for cursors)
* initial support for some DBAPI-2.0 extensions:
- .rownumber attribute for cursors
- .connection attribute for cursors
- .next() and .__iter__() methods to have cursors support the iterator
- all exception objects are exported to the connection object
* implemented microprotocols to adapt arbitrary types to the interface used by
psycopg to bind variables in execute;
* moved qstring, pboolean and mxdatetime to the new adapter layout (binary is
still missing; python 2.3 datetime needs to be written).
* reorganized the whole source tree;
* async core is in place;
* splitted QuotedString objects from mx stuff;
* dropped autotools and moved to pythonic setup.py (needs work.)