summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-10-15 00:58:32 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-10-15 00:58:32 +0100
commitb205764fdde4549c48c27841aa17e6c7f499e808 (patch)
tree1475eb57dc854ea4a1dc93c1c6a567e6fc584e5c /doc
parente7227ce87b8da75fef1a3376ebb47e2bf20f6063 (diff)
parent7a5edff6c66a0410d6fecd4445980aabafc3ab4a (diff)
downloadpsycopg2-b205764fdde4549c48c27841aa17e6c7f499e808.tar.gz
Merge branch 'master' into errors-moduleerrors-module
Diffstat (limited to 'doc')
-rw-r--r--doc/src/advanced.rst20
-rw-r--r--doc/src/conf.py11
-rw-r--r--doc/src/connection.rst62
-rw-r--r--doc/src/cursor.rst81
-rw-r--r--doc/src/errorcodes.rst4
-rw-r--r--doc/src/extensions.rst100
-rw-r--r--doc/src/extras.rst12
-rw-r--r--doc/src/faq.rst12
-rw-r--r--doc/src/index.rst6
-rw-r--r--doc/src/install.rst16
-rw-r--r--doc/src/module.rst6
-rw-r--r--doc/src/sql.rst12
-rw-r--r--doc/src/usage.rst57
13 files changed, 264 insertions, 135 deletions
diff --git a/doc/src/advanced.rst b/doc/src/advanced.rst
index 724cb28..62873e7 100644
--- a/doc/src/advanced.rst
+++ b/doc/src/advanced.rst
@@ -156,7 +156,7 @@ geometric type:
.. |point| replace:: :sql:`point`
-.. _point: http://www.postgresql.org/docs/current/static/datatype-geometric.html#DATATYPE-GEOMETRIC
+.. _point: https://www.postgresql.org/docs/current/static/datatype-geometric.html#DATATYPE-GEOMETRIC
The above function call results in the SQL command::
@@ -259,9 +259,9 @@ documentation), you should keep the connection in `~connection.autocommit`
mode if you wish to receive or send notifications in a timely manner.
.. |LISTEN| replace:: :sql:`LISTEN`
-.. _LISTEN: http://www.postgresql.org/docs/current/static/sql-listen.html
+.. _LISTEN: https://www.postgresql.org/docs/current/static/sql-listen.html
.. |NOTIFY| replace:: :sql:`NOTIFY`
-.. _NOTIFY: http://www.postgresql.org/docs/current/static/sql-notify.html
+.. _NOTIFY: https://www.postgresql.org/docs/current/static/sql-notify.html
Notifications are received after every query execution. If the user is
interested in receiving notifications but not in performing any query, the
@@ -375,7 +375,7 @@ completely non-blocking connection attempt: see the libpq documentation for
|PQconnectStart|_.
.. |PQconnectStart| replace:: `!PQconnectStart()`
-.. _PQconnectStart: http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNECTSTARTPARAMS
+.. _PQconnectStart: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNECTSTARTPARAMS
The same loop should be also used to perform nonblocking queries: after
sending a query via `~cursor.execute()` or `~cursor.callproc()`, call
@@ -484,14 +484,14 @@ psycopg2 scope, as the callback can be tied to the libraries' implementation
details. You can check the `psycogreen`_ project for further informations and
resources about the topic.
-.. _coroutine: http://en.wikipedia.org/wiki/Coroutine
+.. _coroutine: https://en.wikipedia.org/wiki/Coroutine
.. _greenlet: https://pypi.org/project/greenlet/
-.. _green threads: http://en.wikipedia.org/wiki/Green_threads
-.. _Eventlet: http://eventlet.net/
+.. _green threads: https://en.wikipedia.org/wiki/Green_threads
+.. _Eventlet: https://eventlet.net/
.. _gevent: http://www.gevent.org/
-.. _SQLAlchemy: http://www.sqlalchemy.org/
+.. _SQLAlchemy: https://www.sqlalchemy.org/
.. _psycogreen: http://bitbucket.org/dvarrazzo/psycogreen/
-.. __: http://www.postgresql.org/docs/current/static/libpq-async.html
+.. __: https://www.postgresql.org/docs/current/static/libpq-async.html
.. warning::
@@ -536,7 +536,7 @@ Server version 9.4 adds a new feature called *Logical Replication*.
- PostgreSQL `Streaming Replication Protocol`__
- .. __: http://www.postgresql.org/docs/current/static/protocol-replication.html
+ .. __: https://www.postgresql.org/docs/current/static/protocol-replication.html
Logical replication Quick-Start
diff --git a/doc/src/conf.py b/doc/src/conf.py
index 2c52a56..fa22a91 100644
--- a/doc/src/conf.py
+++ b/doc/src/conf.py
@@ -61,9 +61,8 @@ except ImportError:
release = version
intersphinx_mapping = {
- 'py': ('https://docs.python.org/2', None),
- 'py3': ('https://docs.python.org/3', None),
- }
+ 'py': ('https://docs.python.org/3', None),
+}
# Pattern to generate links to the bug tracker
ticket_url = 'https://github.com/psycopg/psycopg2/issues/%s'
@@ -117,12 +116,12 @@ todo_include_todos = False
rst_epilog = """
.. |DBAPI| replace:: DB API 2.0
-.. _DBAPI: http://www.python.org/dev/peps/pep-0249/
+.. _DBAPI: https://www.python.org/dev/peps/pep-0249/
.. _transaction isolation level:
- http://www.postgresql.org/docs/current/static/transaction-iso.html
+ https://www.postgresql.org/docs/current/static/transaction-iso.html
-.. _mx.DateTime: http://www.egenix.com/products/python/mxBase/mxDateTime/
+.. _mx.DateTime: https://www.egenix.com/products/python/mxBase/mxDateTime/
.. |MVCC| replace:: :abbr:`MVCC (Multiversion concurrency control)`
"""
diff --git a/doc/src/connection.rst b/doc/src/connection.rst
index 2910f30..bd192d6 100644
--- a/doc/src/connection.rst
+++ b/doc/src/connection.rst
@@ -198,7 +198,7 @@ The ``connection`` class
.. seealso:: the |PREPARE TRANSACTION|_ PostgreSQL command.
.. |PREPARE TRANSACTION| replace:: :sql:`PREPARE TRANSACTION`
- .. _PREPARE TRANSACTION: http://www.postgresql.org/docs/current/static/sql-prepare-transaction.html
+ .. _PREPARE TRANSACTION: https://www.postgresql.org/docs/current/static/sql-prepare-transaction.html
.. index::
@@ -224,7 +224,7 @@ The ``connection`` class
.. seealso:: the |COMMIT PREPARED|_ PostgreSQL command.
.. |COMMIT PREPARED| replace:: :sql:`COMMIT PREPARED`
- .. _COMMIT PREPARED: http://www.postgresql.org/docs/current/static/sql-commit-prepared.html
+ .. _COMMIT PREPARED: https://www.postgresql.org/docs/current/static/sql-commit-prepared.html
.. index::
@@ -246,7 +246,7 @@ The ``connection`` class
.. seealso:: the |ROLLBACK PREPARED|_ PostgreSQL command.
.. |ROLLBACK PREPARED| replace:: :sql:`ROLLBACK PREPARED`
- .. _ROLLBACK PREPARED: http://www.postgresql.org/docs/current/static/sql-rollback-prepared.html
+ .. _ROLLBACK PREPARED: https://www.postgresql.org/docs/current/static/sql-rollback-prepared.html
.. index::
@@ -267,7 +267,7 @@ The ``connection`` class
transactions initiated by a program using such driver should be
unpacked correctly.
- .. __: http://jdbc.postgresql.org/
+ .. __: https://jdbc.postgresql.org/
Xids returned by `!tpc_recover()` also have extra attributes
`~psycopg2.extensions.Xid.prepared`, `~psycopg2.extensions.Xid.owner`,
@@ -277,7 +277,7 @@ The ``connection`` class
.. seealso:: the |pg_prepared_xacts|_ system view.
.. |pg_prepared_xacts| replace:: `pg_prepared_xacts`
- .. _pg_prepared_xacts: http://www.postgresql.org/docs/current/static/view-pg-prepared-xacts.html
+ .. _pg_prepared_xacts: https://www.postgresql.org/docs/current/static/view-pg-prepared-xacts.html
@@ -309,7 +309,7 @@ The ``connection`` class
|PQcancel|_.
.. |PQcancel| replace:: `!PQcancel()`
- .. _PQcancel: http://www.postgresql.org/docs/current/static/libpq-cancel.html#LIBPQ-PQCANCEL
+ .. _PQcancel: https://www.postgresql.org/docs/current/static/libpq-cancel.html#LIBPQ-PQCANCEL
.. versionadded:: 2.3
@@ -325,10 +325,10 @@ The ``connection`` class
available for recover.
.. |RESET| replace:: :sql:`RESET`
- .. _RESET: http://www.postgresql.org/docs/current/static/sql-reset.html
+ .. _RESET: https://www.postgresql.org/docs/current/static/sql-reset.html
.. |SET SESSION AUTHORIZATION| replace:: :sql:`SET SESSION AUTHORIZATION`
- .. __: http://www.postgresql.org/docs/current/static/sql-set-session-authorization.html
+ .. __: https://www.postgresql.org/docs/current/static/sql-set-session-authorization.html
.. versionadded:: 2.0.12
@@ -366,7 +366,7 @@ The ``connection`` class
`autocommit` attribute.
.. _isolation level:
- http://www.postgresql.org/docs/current/static/transaction-iso.html
+ https://www.postgresql.org/docs/current/static/transaction-iso.html
Arguments set to `!None` (the default for all) will not be changed.
The parameters *isolation_level*, *readonly* and *deferrable* also
@@ -376,11 +376,11 @@ The ``connection`` class
|default_transaction_read_only|__, |default_transaction_deferrable|__.
.. |default_transaction_isolation| replace:: :sql:`default_transaction_isolation`
- .. __: http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION
+ .. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION
.. |default_transaction_read_only| replace:: :sql:`default_transaction_read_only`
- .. __: http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY
+ .. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY
.. |default_transaction_deferrable| replace:: :sql:`default_transaction_deferrable`
- .. __: http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-DEFERRABLE
+ .. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-DEFERRABLE
The function must be invoked with no transaction in progress.
@@ -388,7 +388,7 @@ The ``connection`` class
of the transaction parameters in the server.
.. |SET TRANSACTION| replace:: :sql:`SET TRANSACTION`
- .. _SET TRANSACTION: http://www.postgresql.org/docs/current/static/sql-set-transaction.html
+ .. _SET TRANSACTION: https://www.postgresql.org/docs/current/static/sql-set-transaction.html
.. versionadded:: 2.4.2
@@ -534,7 +534,7 @@ The ``connection`` class
is the encoding defined by the database. It should be one of the
`characters set supported by PostgreSQL`__
- .. __: http://www.postgresql.org/docs/current/static/multibyte.html
+ .. __: https://www.postgresql.org/docs/current/static/multibyte.html
.. index::
@@ -568,7 +568,7 @@ The ``connection`` class
configuration parameters`__ such as ``log_statement``,
``client_min_messages``, ``log_min_duration_statement`` etc.
- .. __: http://www.postgresql.org/docs/current/static/runtime-config-logging.html
+ .. __: https://www.postgresql.org/docs/current/static/runtime-config-logging.html
.. attribute:: notifies
@@ -600,6 +600,24 @@ The ``connection`` class
.. index::
+ pair: Backend; Host
+
+ .. attribute:: host
+
+ The server host name of the active connection.
+
+ This can be a host name, an IP address, or a directory path if the
+ connection is via Unix socket. (The path case can be distinguished
+ because it will always be an absolute path, beginning with ``/``.)
+
+ .. seealso:: libpq docs for `PQhost()`__ for details.
+
+ .. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQHOST
+
+ .. versionadded:: 2.8.0
+
+
+ .. index::
pair: Backend; PID
.. method:: get_backend_pid()
@@ -612,7 +630,7 @@ The ``connection`` class
.. seealso:: libpq docs for `PQbackendPID()`__ for details.
- .. __: http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQBACKENDPID
+ .. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQBACKENDPID
.. versionadded:: 2.0.8
@@ -633,7 +651,7 @@ The ``connection`` class
.. seealso:: libpq docs for `PQparameterStatus()`__ for details.
- .. __: http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPARAMETERSTATUS
+ .. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPARAMETERSTATUS
.. versionadded:: 2.0.12
@@ -656,7 +674,7 @@ The ``connection`` class
.. seealso:: libpq docs for `PQconninfo()`__ for details.
- .. __: http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNINFO
+ .. __: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNINFO
.. versionadded:: 2.7
@@ -673,7 +691,7 @@ The ``connection`` class
.. seealso:: libpq docs for `PQtransactionStatus()`__ for details.
- .. __: http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQTRANSACTIONSTATUS
+ .. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQTRANSACTIONSTATUS
.. index::
@@ -688,7 +706,7 @@ The ``connection`` class
.. seealso:: libpq docs for `PQprotocolVersion()`__ for details.
- .. __: http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPROTOCOLVERSION
+ .. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPROTOCOLVERSION
.. versionadded:: 2.0.12
@@ -706,7 +724,7 @@ The ``connection`` class
.. seealso:: libpq docs for `PQserverVersion()`__ for details.
- .. __: http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQSERVERVERSION
+ .. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQSERVERVERSION
.. versionadded:: 2.0.12
@@ -743,7 +761,7 @@ The ``connection`` class
`~psycopg2.extensions.lobject` to be instantiated.
.. |lo_import| replace:: `!lo_import()`
- .. _lo_import: http://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-IMPORT
+ .. _lo_import: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-IMPORT
Available values for *mode* are:
diff --git a/doc/src/cursor.rst b/doc/src/cursor.rst
index 5a6935e..1d7098f 100644
--- a/doc/src/cursor.rst
+++ b/doc/src/cursor.rst
@@ -37,46 +37,49 @@ The ``cursor`` class
.. attribute:: description
- This read-only attribute is a sequence of 7-item sequences.
-
- Each of these sequences is a named tuple (a regular tuple if
- :func:`collections.namedtuple` is not available) containing information
- describing one result column:
-
- 0. `!name`: the name of the column returned.
- 1. `!type_code`: the PostgreSQL OID of the column. You can use the
- |pg_type|_ system table to get more informations about the type.
- This is the value used by Psycopg to decide what Python type use
- to represent the value. See also
- :ref:`type-casting-from-sql-to-python`.
- 2. `!display_size`: the actual length of the column in bytes.
- Obtaining this value is computationally intensive, so it is
- always `!None` unless the :envvar:`PSYCOPG_DISPLAY_SIZE` parameter
- is set at compile time. See also PQgetlength_.
- 3. `!internal_size`: the size in bytes of the column associated to
- this column on the server. Set to a negative value for
- variable-size types See also PQfsize_.
- 4. `!precision`: total number of significant digits in columns of
- type |NUMERIC|_. `!None` for other types.
- 5. `!scale`: count of decimal digits in the fractional part in
- columns of type |NUMERIC|. `!None` for other types.
- 6. `!null_ok`: always `!None` as not easy to retrieve from the libpq.
-
- This attribute will be `!None` for operations that do not return rows
- or if the cursor has not had an operation invoked via the
- |execute*|_ methods yet.
-
- .. |pg_type| replace:: :sql:`pg_type`
- .. _pg_type: http://www.postgresql.org/docs/current/static/catalog-pg-type.html
- .. _PQgetlength: http://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQGETLENGTH
- .. _PQfsize: http://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQFSIZE
- .. _NUMERIC: http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL
- .. |NUMERIC| replace:: :sql:`NUMERIC`
+ Read-only attribute describing the result of a query. It is a
+ sequence of `~psycopg2.extensions.Column` instances, each one
+ describing one result column in order. The attribute is `!None` for
+ operations that do not return rows or if the cursor has not had an
+ operation invoked via the |execute*|_ methods yet.
+
+ For compatibility with the DB-API, every object can be unpacked as a
+ 7-items sequence: the attributes retuned this way are the following.
+ For further details and other attributes available check the
+ `~psycopg2.extensions.Column` documentation.
+
+ 0. `~psycopg2.extensions.Column.name`: the name of the column returned.
+
+ 1. `~psycopg2.extensions.Column.type_code`: the PostgreSQL OID of the
+ column.
+
+ 2. `~psycopg2.extensions.Column.display_size`: the actual length of
+ the column in bytes.
+
+ 3. `~psycopg2.extensions.Column.internal_size`: the size in bytes of
+ the column associated to this column on the server.
+
+ 4. `~psycopg2.extensions.Column.precision`: total number of
+ significant digits in columns of type |NUMERIC|. `!None`
+ for other types.
+
+ 5. `~psycopg2.extensions.Column.scale`: count of decimal digits in
+ the fractional part in columns of type |NUMERIC|. `!None`
+ for other types.
+
+ 6. `~psycopg2.extensions.Column.null_ok`: always `!None` as not easy
+ to retrieve from the libpq.
.. versionchanged:: 2.4
if possible, columns descriptions are named tuple instead of
regular tuples.
+ .. versionchanged:: 2.8
+ columns descriptions are instances of `!Column`, exposing extra
+ attributes.
+
+ .. |NUMERIC| replace:: :sql:`NUMERIC`
+
.. method:: close()
Close the cursor now (rather than whenever `del` is executed).
@@ -129,7 +132,7 @@ The ``cursor`` class
backward scroll (see the |declare-notes|__).
.. |declare-notes| replace:: :sql:`DECLARE` notes
- .. __: http://www.postgresql.org/docs/current/static/sql-declare.html#SQL-DECLARE-NOTES
+ .. __: https://www.postgresql.org/docs/current/static/sql-declare.html#SQL-DECLARE-NOTES
.. note::
@@ -430,10 +433,10 @@ The ``cursor`` class
more flexibility.
.. |CREATE-TABLE| replace:: :sql:`CREATE TABLE`
- .. __: http://www.postgresql.org/docs/current/static/sql-createtable.html
+ .. __: https://www.postgresql.org/docs/current/static/sql-createtable.html
.. |INSERT-RETURNING| replace:: :sql:`INSERT ... RETURNING`
- .. __: http://www.postgresql.org/docs/current/static/sql-insert.html
+ .. __: https://www.postgresql.org/docs/current/static/sql-insert.html
.. attribute:: query
@@ -620,7 +623,7 @@ The ``cursor`` class
...
.. |COPY| replace:: :sql:`COPY`
- .. __: http://www.postgresql.org/docs/current/static/sql-copy.html
+ .. __: https://www.postgresql.org/docs/current/static/sql-copy.html
.. versionadded:: 2.0.6
diff --git a/doc/src/errorcodes.rst b/doc/src/errorcodes.rst
index ab49afb..f852aa6 100644
--- a/doc/src/errorcodes.rst
+++ b/doc/src/errorcodes.rst
@@ -39,7 +39,7 @@ From PostgreSQL documentation:
.. seealso:: `PostgreSQL Error Codes table`__
- .. __: http://www.postgresql.org/docs/current/static/errcodes-appendix.html#ERRCODES-TABLE
+ .. __: https://www.postgresql.org/docs/current/static/errcodes-appendix.html#ERRCODES-TABLE
An example of the available constants defined in the module:
@@ -50,7 +50,7 @@ An example of the available constants defined in the module:
'42P01'
Constants representing all the error values defined by PostgreSQL versions
-between 8.1 and 10 are included in the module.
+between 8.1 and 11 are included in the module.
.. autofunction:: lookup(code)
diff --git a/doc/src/extensions.rst b/doc/src/extensions.rst
index 48bcdc2..f331721 100644
--- a/doc/src/extensions.rst
+++ b/doc/src/extensions.rst
@@ -94,7 +94,7 @@ introspection etc.
The method uses the efficient |lo_export|_ libpq function.
.. |lo_export| replace:: `!lo_export()`
- .. _lo_export: http://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-EXPORT
+ .. _lo_export: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-EXPORT
.. method:: seek(offset, whence=0)
@@ -125,7 +125,7 @@ introspection etc.
libpq function.
.. |lo_truncate| replace:: `!lo_truncate()`
- .. _lo_truncate: http://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-TRUNCATE
+ .. _lo_truncate: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-TRUNCATE
.. versionadded:: 2.2.0
@@ -154,6 +154,80 @@ introspection etc.
Close the object and remove it from the database.
+.. class:: Column
+
+ Description of one result column, exposed as items of the
+ `cursor.description` sequence.
+
+ .. versionadded:: 2.8
+
+ in previous version the `!description` attribute was a sequence of
+ simple tuples or namedtuples.
+
+ .. attribute:: name
+
+ The name of the column returned.
+
+ .. attribute:: type_code
+
+ The PostgreSQL OID of the column. You can use the |pg_type|_ system
+ table to get more informations about the type. This is the value used
+ by Psycopg to decide what Python type use to represent the value. See
+ also :ref:`type-casting-from-sql-to-python`.
+
+ .. attribute:: display_size
+
+ The actual length of the column in bytes. Obtaining this value is
+ computationally intensive, so it is always `!None` unless the
+ :envvar:`PSYCOPG_DISPLAY_SIZE` parameter is set at compile time. See
+ also PQgetlength_.
+
+ .. attribute:: internal_size
+
+ The size in bytes of the column associated to this column on the
+ server. Set to a negative value for variable-size types See also
+ PQfsize_.
+
+ .. attribute:: precision
+
+ Total number of significant digits in columns of type |NUMERIC|_.
+ `!None` for other types.
+
+ .. attribute:: scale
+
+ Count of decimal digits in the fractional part in columns of type
+ |NUMERIC|. `!None` for other types.
+
+ .. attribute:: null_ok
+
+ Always `!None` as not easy to retrieve from the libpq.
+
+ .. attribute:: table_oid
+
+ The oid of the table from which the column was fetched (matching
+ :sql:`pg_class.oid`). `!None` if the column is not a simple reference
+ to a table column. See also PQftable_.
+
+ .. versionadded:: 2.8
+
+ .. attribute:: table_column
+
+ The number of the column (within its table) making up the result
+ (matching :sql:`pg_attribute.attnum`, so it will start from 1).
+ `!None` if the column is not a simple reference to a table column. See
+ also PQftablecol_.
+
+ .. versionadded:: 2.8
+
+ .. |pg_type| replace:: :sql:`pg_type`
+ .. _pg_type: https://www.postgresql.org/docs/current/static/catalog-pg-type.html
+ .. _PQgetlength: https://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQGETLENGTH
+ .. _PQfsize: https://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQFSIZE
+ .. _PQftable: https://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQFTABLE
+ .. _PQftablecol: https://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQFTABLECOL
+ .. _NUMERIC: https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL
+ .. |NUMERIC| replace:: :sql:`NUMERIC`
+
.. autoclass:: Notify(pid, channel, payload='')
:members: pid, channel, payload
@@ -186,6 +260,7 @@ introspection etc.
message_primary
schema_name
severity
+ severity_nonlocalized
source_file
source_function
source_line
@@ -198,6 +273,9 @@ introspection etc.
not all the fields are available for all the errors and for all the
server versions.
+ .. versionadded:: 2.8
+ The `!severity_nonlocalized` attribute.
+
.. _sql-adaptation-objects:
@@ -423,8 +501,8 @@ details.
Used by Psycopg when adapting or casting unicode strings. See
:ref:`unicode-handling`.
- .. __: http://www.postgresql.org/docs/current/static/multibyte.html
- .. __: http://docs.python.org/library/codecs.html#standard-encodings
+ .. __: https://www.postgresql.org/docs/current/static/multibyte.html
+ .. __: https://docs.python.org/library/codecs.html#standard-encodings
@@ -497,7 +575,7 @@ Other functions
.. seealso:: libpq docs for `PQlibVersion()`__.
- .. __: http://www.postgresql.org/docs/current/static/libpq-misc.html#LIBPQ-PQLIBVERSION
+ .. __: https://www.postgresql.org/docs/current/static/libpq-misc.html#LIBPQ-PQLIBVERSION
.. function:: make_dsn(dsn=None, \*\*kwargs)
@@ -531,7 +609,7 @@ Other functions
`connection URIs`__ are only supported from libpq 9.2). Raise
`~psycopg2.ProgrammingError` if the *dsn* is not valid.
- .. __: http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
+ .. __: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
Example::
@@ -545,7 +623,7 @@ Other functions
.. seealso:: libpq docs for `PQconninfoParse()`__.
- .. __: http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNINFOPARSE
+ .. __: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNINFOPARSE
.. function:: quote_ident(str, scope)
@@ -559,7 +637,7 @@ Other functions
.. seealso:: libpq docs for `PQescapeIdentifier()`__
- .. __: http://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQESCAPEIDENTIFIER
+ .. __: https://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQESCAPEIDENTIFIER
.. method:: encrypt_password(password, user, scope=None, algorithm=None)
@@ -644,7 +722,7 @@ methods. The level can be set to one of the following constants:
.. seealso:: `Read Committed Isolation Level`__ in PostgreSQL
documentation.
- .. __: http://www.postgresql.org/docs/current/static/transaction-iso.html#XACT-READ-COMMITTED
+ .. __: https://www.postgresql.org/docs/current/static/transaction-iso.html#XACT-READ-COMMITTED
.. data:: ISOLATION_LEVEL_REPEATABLE_READ
@@ -668,7 +746,7 @@ methods. The level can be set to one of the following constants:
.. seealso:: `Repeatable Read Isolation Level`__ in PostgreSQL
documentation.
- .. __: http://www.postgresql.org/docs/current/static/transaction-iso.html#XACT-REPEATABLE-READ
+ .. __: https://www.postgresql.org/docs/current/static/transaction-iso.html#XACT-REPEATABLE-READ
.. data:: ISOLATION_LEVEL_SERIALIZABLE
@@ -687,7 +765,7 @@ methods. The level can be set to one of the following constants:
.. seealso:: `Serializable Isolation Level`__ in PostgreSQL documentation.
- .. __: http://www.postgresql.org/docs/current/static/transaction-iso.html#XACT-SERIALIZABLE
+ .. __: https://www.postgresql.org/docs/current/static/transaction-iso.html#XACT-SERIALIZABLE
.. data:: ISOLATION_LEVEL_DEFAULT
diff --git a/doc/src/extras.rst b/doc/src/extras.rst
index 15f35e8..e911782 100644
--- a/doc/src/extras.rst
+++ b/doc/src/extras.rst
@@ -542,10 +542,10 @@ fields to JSON) you can use the `register_json()` function.
The Python :py:mod:`json` module is used by default to convert Python objects
to JSON and to parse data from the database.
-.. _JSON: http://www.json.org/
+.. _JSON: https://www.json.org/
.. |pgjson| replace:: :sql:`json`
.. |jsonb| replace:: :sql:`jsonb`
-.. _pgjson: http://www.postgresql.org/docs/current/static/datatype-json.html
+.. _pgjson: https://www.postgresql.org/docs/current/static/datatype-json.html
In order to pass a Python object to the database as query argument you can use
the `Json` adapter::
@@ -664,7 +664,7 @@ can be enabled using the `register_hstore()` function.
.. |hstore| replace:: :sql:`hstore`
-.. _hstore: http://www.postgresql.org/docs/current/static/hstore.html
+.. _hstore: https://www.postgresql.org/docs/current/static/hstore.html
@@ -686,7 +686,7 @@ after a table row type) into a Python named tuple, or into a regular tuple if
:py:func:`collections.namedtuple` is not found.
.. |CREATE TYPE| replace:: :sql:`CREATE TYPE`
-.. _CREATE TYPE: http://www.postgresql.org/docs/current/static/sql-createtype.html
+.. _CREATE TYPE: https://www.postgresql.org/docs/current/static/sql-createtype.html
.. doctest::
@@ -800,7 +800,7 @@ PostgreSQL |range|_ types. Builtin |range| types are supported out-of-the-box;
user-defined |range| types can be adapted using `register_range()`.
.. |range| replace:: :sql:`range`
-.. _range: http://www.postgresql.org/docs/current/static/rangetypes.html
+.. _range: https://www.postgresql.org/docs/current/static/rangetypes.html
.. autoclass:: Range
@@ -809,7 +809,7 @@ user-defined |range| types can be adapted using `register_range()`.
features: it doesn't perform normalization and doesn't implement all the
operators__ supported by the database.
- .. __: http://www.postgresql.org/docs/current/static/functions-range.html#RANGE-OPERATORS-TABLE
+ .. __: https://www.postgresql.org/docs/current/static/functions-range.html#RANGE-OPERATORS-TABLE
`!Range` objects are immutable, hashable, and support the ``in`` operator
(checking if an element is within the range). They can be tested for
diff --git a/doc/src/faq.rst b/doc/src/faq.rst
index 5824d2b..432e994 100644
--- a/doc/src/faq.rst
+++ b/doc/src/faq.rst
@@ -40,7 +40,7 @@ I receive the error *current transaction is aborted, commands ignored until end
PostgreSQL supports nested transactions using the |SAVEPOINT|_ command).
.. |SAVEPOINT| replace:: :sql:`SAVEPOINT`
- .. _SAVEPOINT: http://www.postgresql.org/docs/current/static/sql-savepoint.html
+ .. _SAVEPOINT: https://www.postgresql.org/docs/current/static/sql-savepoint.html
.. _faq-transaction-aborted-multiprocess:
@@ -184,8 +184,8 @@ Transferring binary data from PostgreSQL 9.0 doesn't work.
session before reading binary data;
- upgrade the libpq library on the client to at least 9.0.
- .. __: http://www.postgresql.org/docs/current/static/datatype-binary.html
- .. __: http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-BYTEA-OUTPUT
+ .. __: https://www.postgresql.org/docs/current/static/datatype-binary.html
+ .. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-BYTEA-OUTPUT
.. _faq-array:
@@ -318,7 +318,7 @@ I can't compile `!psycopg2`: the compiler says *error: libpq-fe.h: No such file
:program:`pg_config` at install time and the libpq at runtime.
.. |lo_truncate| replace:: `!lo_truncate()`
- .. _lo_truncate: http://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-TRUNCATE
+ .. _lo_truncate: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-TRUNCATE
.. _faq-import-mod_wsgi:
@@ -332,5 +332,5 @@ Psycopg raises *ImportError: cannot import name tz* on import in mod_wsgi / ASP,
use the WSGIPythonEggs__ directive.
.. _egg: http://peak.telecommunity.com/DevCenter/PythonEggs
- .. __: http://stackoverflow.com/questions/2192323/what-is-the-python-egg-cache-python-egg-cache
- .. __: http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonEggs
+ .. __: https://stackoverflow.com/questions/2192323/what-is-the-python-egg-cache-python-egg-cache
+ .. __: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIPythonEggs.html
diff --git a/doc/src/index.rst b/doc/src/index.rst
index 4e920cb..3f2e401 100644
--- a/doc/src/index.rst
+++ b/doc/src/index.rst
@@ -24,9 +24,9 @@ Psycopg 2 is both Unicode and Python 3 friendly.
.. _Psycopg: http://initd.org/psycopg/
-.. _PostgreSQL: http://www.postgresql.org/
-.. _Python: http://www.python.org/
-.. _libpq: http://www.postgresql.org/docs/current/static/libpq.html
+.. _PostgreSQL: https://www.postgresql.org/
+.. _Python: https://www.python.org/
+.. _libpq: https://www.postgresql.org/docs/current/static/libpq.html
.. rubric:: Contents
diff --git a/doc/src/install.rst b/doc/src/install.rst
index f60b3c8..34845b0 100644
--- a/doc/src/install.rst
+++ b/doc/src/install.rst
@@ -12,11 +12,11 @@ to use Psycopg on a different Python implementation (PyPy, Jython, IronPython)
there is an experimental `porting of Psycopg for Ctypes`__, but it is not as
mature as the C implementation yet.
-.. _PostgreSQL: http://www.postgresql.org/
-.. _Python: http://www.python.org/
-.. _libpq: http://www.postgresql.org/docs/current/static/libpq.html
-.. _CPython: http://en.wikipedia.org/wiki/CPython
-.. _Ctypes: http://docs.python.org/library/ctypes.html
+.. _PostgreSQL: https://www.postgresql.org/
+.. _Python: https://www.python.org/
+.. _libpq: https://www.postgresql.org/docs/current/static/libpq.html
+.. _CPython: https://en.wikipedia.org/wiki/CPython
+.. _Ctypes: https://docs.python.org/library/ctypes.html
.. __: https://github.com/mvantellingen/psycopg2-ctypes
@@ -33,7 +33,7 @@ The current `!psycopg2` implementation supports:
NOTE: keep consistent with setup.py and the /features/ page.
- Python version 2.7
-- Python 3 versions from 3.4 to 3.6
+- Python 3 versions from 3.4 to 3.7
- PostgreSQL server versions from 7.4 to 10
- PostgreSQL client library version from 9.1
@@ -152,7 +152,7 @@ using something like ``pip install -U pip``), then you can run:
.. __: PyPI-binary_
.. _PyPI-binary: https://pypi.org/project/psycopg2-binary/
-.. _wheel: http://pythonwheels.com/
+.. _wheel: https://pythonwheels.com/
.. note::
@@ -188,7 +188,7 @@ displayed, `psycopg2-binary` has become a separate package, and from 2.8 it
has become the only way to install the binary package.
If you are using psycopg 2.7 and you want to disable the use of wheel binary
-packages, relying on the system system libraries available on your client, you
+packages, relying on the system libraries available on your client, you
can use the :command:`pip` |--no-binary option|__, e.g.:
.. code-block:: console
diff --git a/doc/src/module.rst b/doc/src/module.rst
index ef73b58..6268962 100644
--- a/doc/src/module.rst
+++ b/doc/src/module.rst
@@ -50,11 +50,11 @@ The module interface respects the standard defined in the |DBAPI|_.
using `environment variables`__.
.. __:
- .. _connstring: http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
+ .. _connstring: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
.. __:
- .. _connparams: http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
+ .. _connparams: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
.. __:
- .. _connenvvars: http://www.postgresql.org/docs/current/static/libpq-envars.html
+ .. _connenvvars: https://www.postgresql.org/docs/current/static/libpq-envars.html
Using the *connection_factory* parameter a different class or
connections factory can be specified. It should be a callable object
diff --git a/doc/src/sql.rst b/doc/src/sql.rst
index fe807c6..9cd18e7 100644
--- a/doc/src/sql.rst
+++ b/doc/src/sql.rst
@@ -77,16 +77,26 @@ to cursor methods such as `~cursor.execute()`, `~cursor.executemany()`,
.. autoclass:: Identifier
- .. autoattribute:: string
+ .. versionchanged:: 2.8
+ added support for multiple strings.
+
+ .. autoattribute:: strings
+
+ .. versionadded:: 2.8
+ previous verions only had a `!string` attribute. The attribute
+ still exists but is deprecate and will only work if the
+ `!Identifier` wraps a single string.
.. autoclass:: Literal
.. autoattribute:: wrapped
+
.. autoclass:: Placeholder
.. autoattribute:: name
+
.. autoclass:: Composed
.. autoattribute:: seq
diff --git a/doc/src/usage.rst b/doc/src/usage.rst
index db8674c..e9416e3 100644
--- a/doc/src/usage.rst
+++ b/doc/src/usage.rst
@@ -198,8 +198,8 @@ called `SQL injection`_ and is known to be one of the most widespread forms of
attack to database servers. Before continuing, please print `this page`__ as a
memo and hang it onto your desk.
-.. _SQL injection: http://en.wikipedia.org/wiki/SQL_injection
-.. __: http://xkcd.com/327/
+.. _SQL injection: https://en.wikipedia.org/wiki/SQL_injection
+.. __: https://xkcd.com/327/
Psycopg can `automatically convert Python objects to and from SQL
literals`__: using this feature your code will be more robust and
@@ -221,7 +221,28 @@ argument of the `~cursor.execute()` method::
>>> cur.execute(SQL, data) # Note: no % operator
+Values containing backslashes and LIKE
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Unlike in Python, the backslash (`\\`) is not used as an escape
+character *except* in patterns used with `LIKE` and `ILIKE` where they
+are needed to escape the `%` and `_` characters.
+
+This can lead to confusing situations::
+
+ >>> path = r'C:\Users\Bobby.Tables'
+ >>> cur.execute('INSERT INTO mytable(path) VALUES (%s)', (path,))
+ >>> cur.execute('SELECT * FROM mytable WHERE path LIKE %s', (path,))
+ >>> cur.fetchall()
+ []
+
+The solution is to specify an `ESCAPE` character of `''` (empty string)
+in your `LIKE` query::
+
+ >>> cur.execute("SELECT * FROM mytable WHERE path LIKE %s ESCAPE ''", (path,))
+
+
+
.. index::
single: Adaptation
pair: Objects; Adaptation
@@ -351,7 +372,7 @@ converted into `!Decimal`.
This of course may imply a loss of precision.
.. seealso:: `PostgreSQL numeric types
- <http://www.postgresql.org/docs/current/static/datatype-numeric.html>`__
+ <https://www.postgresql.org/docs/current/static/datatype-numeric.html>`__
.. index::
@@ -391,8 +412,8 @@ defined on the database connection (the `PostgreSQL encoding`__, available in
>>> cur.execute("INSERT INTO test (num, data) VALUES (%s,%s);", (74, u))
-.. __: http://www.postgresql.org/docs/current/static/multibyte.html
-.. __: http://docs.python.org/library/codecs.html#standard-encodings
+.. __: https://www.postgresql.org/docs/current/static/multibyte.html
+.. __: https://docs.python.org/library/codecs.html
When reading data from the database, in Python 2 the strings returned are
usually 8 bit `!str` objects encoded in the database client encoding::
@@ -465,7 +486,7 @@ type `!str`). Any object implementing the `Revised Buffer Protocol`__ should
be usable as binary type. Received data is returned as `!buffer` (in Python 2)
or `!memoryview` (in Python 3).
-.. __: http://www.python.org/dev/peps/pep-3118/
+.. __: https://www.python.org/dev/peps/pep-3118/
.. versionchanged:: 2.4
only strings were supported before.
@@ -494,8 +515,8 @@ or `!memoryview` (in Python 3).
server configuration file or in the client session (using a query such as
``SET bytea_output TO escape;``) before receiving binary data.
- .. __: http://www.postgresql.org/docs/current/static/datatype-binary.html
- .. __: http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-BYTEA-OUTPUT
+ .. __: https://www.postgresql.org/docs/current/static/datatype-binary.html
+ .. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-BYTEA-OUTPUT
.. index::
@@ -527,7 +548,7 @@ the same way::
"SELECT '38 days 6027.425337 seconds';"
.. seealso:: `PostgreSQL date/time types
- <http://www.postgresql.org/docs/current/static/datatype-datetime.html>`__
+ <https://www.postgresql.org/docs/current/static/datatype-datetime.html>`__
.. index::
@@ -622,7 +643,7 @@ Python lists are converted into PostgreSQL :sql:`ARRAY`\ s::
Furthermore :sql:`ANY` can also work with empty lists, whereas :sql:`IN ()`
is a SQL syntax error.
- .. __: http://www.postgresql.org/docs/current/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME
+ .. __: https://www.postgresql.org/docs/current/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME
.. note::
@@ -846,7 +867,7 @@ lifetime extends well after `~connection.commit()`, calling
.. |DECLARE| replace:: :sql:`DECLARE`
-.. _DECLARE: http://www.postgresql.org/docs/current/static/sql-declare.html
+.. _DECLARE: https://www.postgresql.org/docs/current/static/sql-declare.html
@@ -876,7 +897,7 @@ forked processes`__, so when using a module such as `multiprocessing` or a
forking web deploy method such as FastCGI make sure to create the connections
*after* the fork.
-.. __: http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNECT
+.. __: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNECT
Connections shouldn't be shared either by different green threads: see
:ref:`green-support` for further details.
@@ -920,7 +941,7 @@ Please refer to the documentation of the single methods for details and
examples.
.. |COPY| replace:: :sql:`COPY`
-.. __: http://www.postgresql.org/docs/current/static/sql-copy.html
+.. __: https://www.postgresql.org/docs/current/static/sql-copy.html
@@ -937,7 +958,7 @@ access to user data that is stored in a special large-object structure. They
are useful with data values too large to be manipulated conveniently as a
whole.
-.. __: http://www.postgresql.org/docs/current/static/largeobjects.html
+.. __: https://www.postgresql.org/docs/current/static/largeobjects.html
Psycopg allows access to the large object using the
`~psycopg2.extensions.lobject` class. Objects are generated using the
@@ -948,9 +969,9 @@ Psycopg large object support efficient import/export with file system files
using the |lo_import|_ and |lo_export|_ libpq functions.
.. |lo_import| replace:: `!lo_import()`
-.. _lo_import: http://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-IMPORT
+.. _lo_import: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-IMPORT
.. |lo_export| replace:: `!lo_export()`
-.. _lo_export: http://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-EXPORT
+.. _lo_export: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-EXPORT
.. versionchanged:: 2.6
added support for large objects greated than 2GB. Note that the support is
@@ -1014,5 +1035,5 @@ transactions produced by a Java program.
For further details see the documentation for the above methods.
-.. __: http://www.opengroup.org/bookstore/catalog/c193.htm
-.. __: http://jdbc.postgresql.org/
+.. __: https://publications.opengroup.org/c193
+.. __: https://jdbc.postgresql.org/