Skip to content

Commit 65ebd92

Browse files
gh-92780: Improve sqlite3.Connection.create_collation docs (GH-92790)
Co-authored-by: Alex Waygood <[email protected]> (cherry picked from commit 7ee19e2) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
1 parent fad72d0 commit 65ebd92

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Diff for: Doc/library/sqlite3.rst

+8-11
Original file line numberDiff line numberDiff line change
@@ -518,22 +518,19 @@ Connection Objects
518518

519519
.. method:: create_collation(name, callable)
520520

521-
Creates a collation with the specified *name* and *callable*. The callable will
522-
be passed two string arguments. It should return -1 if the first is ordered
523-
lower than the second, 0 if they are ordered equal and 1 if the first is ordered
524-
higher than the second. Note that this controls sorting (ORDER BY in SQL) so
525-
your comparisons don't affect other SQL operations.
521+
Create a collation named *name* using the collating function *callable*.
522+
*callable* is passed two :class:`string <str>` arguments,
523+
and it should return an :class:`integer <int>`:
526524

527-
Note that the callable will get its parameters as Python bytestrings, which will
528-
normally be encoded in UTF-8.
525+
* ``1`` if the first is ordered higher than the second
526+
* ``-1`` if the first is ordered lower than the second
527+
* ``0`` if they are ordered equal
529528

530-
The following example shows a custom collation that sorts "the wrong way":
529+
The following example shows a reverse sorting collation:
531530

532531
.. literalinclude:: ../includes/sqlite3/collation_reverse.py
533532

534-
To remove a collation, call ``create_collation`` with ``None`` as callable::
535-
536-
con.create_collation("reverse", None)
533+
Remove a collation function by setting *callable* to :const:`None`.
537534

538535
.. versionchanged:: 3.11
539536
The collation name can contain any Unicode character. Earlier, only

0 commit comments

Comments
 (0)