Skip to content

Commit 1885626

Browse files
pythongh-131002: clarify how to enforce sqlite3 column types for generated fields
1 parent 92e5f82 commit 1885626

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Doc/library/sqlite3.rst

+19-18
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ Module functions
290290
:const:`PARSE_DECLTYPES` and :const:`PARSE_COLNAMES`
291291
to enable this.
292292
Column names takes precedence over declared types if both flags are set.
293-
Types cannot be detected for generated fields (for example ``max(data)``),
294-
even when the *detect_types* parameter is set; :class:`str` will be
295-
returned instead.
296293
By default (``0``), type detection is disabled.
297294

298295
:param isolation_level:
@@ -436,21 +433,6 @@ Module constants
436433
old style (pre-Python 3.12) transaction control behaviour.
437434
See :ref:`sqlite3-transaction-control-isolation-level` for more information.
438435

439-
.. data:: PARSE_COLNAMES
440-
441-
Pass this flag value to the *detect_types* parameter of
442-
:func:`connect` to look up a converter function by
443-
using the type name, parsed from the query column name,
444-
as the converter dictionary key.
445-
The type name must be wrapped in square brackets (``[]``).
446-
447-
.. code-block:: sql
448-
449-
SELECT p as "p [point]" FROM test; ! will look up converter "point"
450-
451-
This flag may be combined with :const:`PARSE_DECLTYPES` using the ``|``
452-
(bitwise or) operator.
453-
454436
.. data:: PARSE_DECLTYPES
455437

456438
Pass this flag value to the *detect_types* parameter of
@@ -472,6 +454,25 @@ Module constants
472454
This flag may be combined with :const:`PARSE_COLNAMES` using the ``|``
473455
(bitwise or) operator.
474456

457+
Generated fields (for example ``MAX(data)``) are returned as :class:`str`;
458+
use :const:`!PARSE_COLNAMES` to enforce types for such queries.
459+
460+
.. data:: PARSE_COLNAMES
461+
462+
Pass this flag value to the *detect_types* parameter of
463+
:func:`connect` to look up a converter function by
464+
using the type name, parsed from the query column name,
465+
as the converter dictionary key.
466+
The query column name must be wrapped with double quotes (``"``),
467+
and the type name must be wrapped in square brackets (``[]``),
468+
469+
.. code-block:: sql
470+
471+
SELECT MAX(p) as "p [point]" FROM test; ! will look up converter "point"
472+
473+
This flag may be combined with :const:`PARSE_DECLTYPES` using the ``|``
474+
(bitwise or) operator.
475+
475476
.. data:: SQLITE_OK
476477
SQLITE_DENY
477478
SQLITE_IGNORE

0 commit comments

Comments
 (0)