8000 [3.12] gh-131002: clarify how to enforce sqlite3 column types for gen… · python/cpython@9d23a6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d23a6d

Browse files
[3.12] gh-131002: clarify how to enforce sqlite3 column types for generated fields (GH-131006) (#131386)
(cherry picked from commit f48887f) Co-authored-by: Erlend E. Aasland <erlend@python.org>
1 parent 2601dae commit 9d23a6d

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

Doc/library/sqlite3.rst

Lines changed: 21 additions & 18 deletions
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:
@@ -430,21 +427,6 @@ Module constants
430427
old style (pre-Python 3.12) transaction control behaviour.
431428
See :ref:`sqlite3-transaction-control-isolation-level` for more information.
432429

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

450432
Pass this flag value to the *detect_types* parameter of
@@ -466,6 +448,27 @@ Module constants
466448
This flag may be combined with :const:`PARSE_COLNAMES` using the ``|``
467449
(bitwise or) operator.
468450

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

0 commit comments

Comments
 (0)
0