mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-07-15 18:52:32 +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:
|
New features:
|
||||||
|
|
||||||
- Added `~psycopg2.extensions.encrypt_password()` function (:ticket:`#576`).
|
- 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`).
|
- Added `connection.host` property (:ticket:`#726`).
|
||||||
- `~psycopg2.sql.Identifier` can represent qualified names in SQL composition
|
- `~psycopg2.sql.Identifier` can represent qualified names in SQL composition
|
||||||
(:ticket:`#732`).
|
(:ticket:`#732`).
|
||||||
|
|
|
@ -37,46 +37,49 @@ The ``cursor`` class
|
||||||
|
|
||||||
.. attribute:: description
|
.. 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
|
For compatibility with the DB-API, every object can be unpacked as a
|
||||||
:func:`collections.namedtuple` is not available) containing information
|
7-items sequence: the attributes retuned this way are the following.
|
||||||
describing one result column:
|
For further details and other attributes available check the
|
||||||
|
`~psycopg2.extensions.Column` documentation.
|
||||||
|
|
||||||
0. `!name`: the name of the column returned.
|
0. `~psycopg2.extensions.Column.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
|
1. `~psycopg2.extensions.Column.type_code`: the PostgreSQL OID of the
|
||||||
or if the cursor has not had an operation invoked via the
|
column.
|
||||||
|execute*|_ methods yet.
|
|
||||||
|
|
||||||
.. |pg_type| replace:: :sql:`pg_type`
|
2. `~psycopg2.extensions.Column.display_size`: the actual length of
|
||||||
.. _pg_type: https://www.postgresql.org/docs/current/static/catalog-pg-type.html
|
the column in bytes.
|
||||||
.. _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
|
3. `~psycopg2.extensions.Column.internal_size`: the size in bytes of
|
||||||
.. _NUMERIC: https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL
|
the column associated to this column on the server.
|
||||||
.. |NUMERIC| replace:: :sql:`NUMERIC`
|
|
||||||
|
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
|
.. versionchanged:: 2.4
|
||||||
if possible, columns descriptions are named tuple instead of
|
if possible, columns descriptions are named tuple instead of
|
||||||
regular tuples.
|
regular tuples.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.8
|
||||||
|
columns descriptions are instances of `!Column`, exposing extra
|
||||||
|
attributes.
|
||||||
|
|
||||||
|
.. |NUMERIC| replace:: :sql:`NUMERIC`
|
||||||
|
|
||||||
.. method:: close()
|
.. method:: close()
|
||||||
|
|
||||||
Close the cursor now (rather than whenever `del` is executed).
|
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.
|
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='')
|
.. autoclass:: Notify(pid, channel, payload='')
|
||||||
:members: pid, channel, payload
|
:members: pid, channel, payload
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user