mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-10 19:16:34 +03:00
Added docs for the Column object
This commit is contained in:
parent
f99a8de6d0
commit
6b3d3604bf
3
NEWS
3
NEWS
|
@ -7,6 +7,9 @@ What's new in psycopg 2.8
|
|||
New features:
|
||||
|
||||
- Added `~psycopg2.extensions.encrypt_password()` function (:ticket:`#576`).
|
||||
- Added `~psycopg2.extensions.Column.table_oid` and
|
||||
`~psycopg2.extensions.Column.table_column` attributes on `cursor.description`
|
||||
items (:ticket:`#661`).
|
||||
- Added `connection.host` property (:ticket:`#726`).
|
||||
- `~psycopg2.sql.Identifier` can represent qualified names in SQL composition
|
||||
(:ticket:`#732`).
|
||||
|
|
|
@ -37,46 +37,49 @@ The ``cursor`` class
|
|||
|
||||
.. attribute:: description
|
||||
|
||||
This read-only attribute is a sequence of 7-item sequences.
|
||||
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.
|
||||
|
||||
Each of these sequences is a named tuple (a regular tuple if
|
||||
:func:`collections.namedtuple` is not available) containing information
|
||||
describing one result column:
|
||||
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. `!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.
|
||||
0. `~psycopg2.extensions.Column.name`: the name of the column returned.
|
||||
|
||||
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.
|
||||
1. `~psycopg2.extensions.Column.type_code`: the PostgreSQL OID of the
|
||||
column.
|
||||
|
||||
.. |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
|
||||
.. _NUMERIC: https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL
|
||||
.. |NUMERIC| replace:: :sql:`NUMERIC`
|
||||
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).
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user