]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-131002: clarify how to enforce sqlite3 column types for generated fields...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 18 Mar 2025 11:10:01 +0000 (12:10 +0100)
committerGitHub <noreply@github.com>
Tue, 18 Mar 2025 11:10:01 +0000 (12:10 +0100)
(cherry picked from commit f48887fb97651c02c5e412a75ed8b51a4ca11e6a)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Doc/library/sqlite3.rst

index 3078ec29afe1f033e1d99525e9a3430dc77a3c56..259a35c1c258757049c8f5001eaeb4151bb8b14d 100644 (file)
@@ -290,9 +290,6 @@ Module functions
        :const:`PARSE_DECLTYPES` and :const:`PARSE_COLNAMES`
        to enable this.
        Column names takes precedence over declared types if both flags are set.
-       Types cannot be detected for generated fields (for example ``max(data)``),
-       even when the *detect_types* parameter is set; :class:`str` will be
-       returned instead.
        By default (``0``), type detection is disabled.
 
    :param isolation_level:
@@ -430,21 +427,6 @@ Module constants
    old style (pre-Python 3.12) transaction control behaviour.
    See :ref:`sqlite3-transaction-control-isolation-level` for more information.
 
-.. data:: PARSE_COLNAMES
-
-   Pass this flag value to the *detect_types* parameter of
-   :func:`connect` to look up a converter function by
-   using the type name, parsed from the query column name,
-   as the converter dictionary key.
-   The type name must be wrapped in square brackets (``[]``).
-
-   .. code-block:: sql
-
-      SELECT p as "p [point]" FROM test;  ! will look up converter "point"
-
-   This flag may be combined with :const:`PARSE_DECLTYPES` using the ``|``
-   (bitwise or) operator.
-
 .. data:: PARSE_DECLTYPES
 
    Pass this flag value to the *detect_types* parameter of
@@ -466,6 +448,27 @@ Module constants
    This flag may be combined with :const:`PARSE_COLNAMES` using the ``|``
    (bitwise or) operator.
 
+   .. note::
+
+      Generated fields (for example ``MAX(p)``) are returned as :class:`str`.
+      Use :const:`!PARSE_COLNAMES` to enforce types for such queries.
+
+.. data:: PARSE_COLNAMES
+
+   Pass this flag value to the *detect_types* parameter of
+   :func:`connect` to look up a converter function by
+   using the type name, parsed from the query column name,
+   as the converter dictionary key.
+   The query column name must be wrapped in double quotes (``"``)
+   and the type name must be wrapped in square brackets (``[]``).
+
+   .. code-block:: sql
+
+      SELECT MAX(p) as "p [point]" FROM test;  ! will look up converter "point"
+
+   This flag may be combined with :const:`PARSE_DECLTYPES` using the ``|``
+   (bitwise or) operator.
+
 .. data:: SQLITE_OK
           SQLITE_DENY
           SQLITE_IGNORE