diff options
author | Erlend E. Aasland <erlend@python.org> | 2025-03-17 23:26:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-17 22:26:27 +0000 |
commit | f48887fb97651c02c5e412a75ed8b51a4ca11e6a (patch) | |
tree | 24c851feeb7ea8169d49ff3f9f02cd0806276349 | |
parent | 149fbb01f2f49e6d87ab916d099d19c57f7ed80a (diff) | |
download | cpython-f48887fb97651c02c5e412a75ed8b51a4ca11e6a.tar.gz cpython-f48887fb97651c02c5e412a75ed8b51a4ca11e6a.zip |
gh-131002: clarify how to enforce sqlite3 column types for generated fields (#131006)
-rw-r--r-- | Doc/library/sqlite3.rst | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 4de09e14062..c615650b622 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -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: @@ -436,21 +433,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 @@ -472,6 +454,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 |