]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
various improvements to the docs
authorFederico Caselli <cfederico87@gmail.com>
Thu, 13 Feb 2025 18:54:11 +0000 (19:54 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 13 Feb 2025 18:54:11 +0000 (19:54 +0100)
- add create table with partition examples in mysql

Change-Id: Idc5c35519a0812f1d63be95c14afb9ce2b00ea93
(cherry picked from commit 9f11b63109cc4d1c5c0f268424fa83bb61460710)

doc/build/orm/declarative_tables.rst
lib/sqlalchemy/dialects/mysql/base.py

index 2ec15e3bf58d34d5e63e5d0c8521d1613587bb18..a4b5cbfe66cd534b9e70b6078e82c0349a023e64 100644 (file)
@@ -423,7 +423,7 @@ allow mapping database types that can support multiple Python types, such as
 
 The above example maps the union of ``list[int]`` and ``list[str]`` to the Postgresql
 :class:`_postgresql.JSONB` datatype, while naming a union of ``float,
-str, bool`` will match to the :class:`.JSON` datatype.   An equivalent
+str, bool`` will match to the :class:`_types.JSON` datatype.   An equivalent
 union, stated in the :class:`_orm.Mapped` construct, will match into the
 corresponding entry in the type map.
 
index 1314ee3debf2378521af923a43ece418cf740a69..4a52d1b67a7320d203a92fd02fbd0485b7f27500 100644 (file)
@@ -182,6 +182,31 @@ For fully atomic transactions as well as support for foreign key
 constraints, all participating ``CREATE TABLE`` statements must specify a
 transactional engine, which in the vast majority of cases is ``InnoDB``.
 
+Partitioning can similarly be specified using similar options.
+In the example below the create table will specify ``PARTITION_BY``,
+``PARTITIONS``, ``SUBPARTITIONS`` and ``SUBPARTITION_BY``::
+
+    # can also use mariadb_* prefix
+    Table(
+        "testtable",
+        MetaData(),
+        Column("id", Integer(), primary_key=True, autoincrement=True),
+        Column("other_id", Integer(), primary_key=True, autoincrement=False),
+        mysql_partitions="2",
+        mysql_partition_by="KEY(other_id)",
+        mysql_subpartition_by="HASH(some_expr)",
+        mysql_subpartitions="2",
+    )
+
+This will render:
+
+.. sourcecode:: sql
+
+    CREATE TABLE testtable (
+            id INTEGER NOT NULL AUTO_INCREMENT,
+            other_id INTEGER NOT NULL,
+            PRIMARY KEY (id, other_id)
+    )PARTITION BY KEY(other_id) PARTITIONS 2 SUBPARTITION BY HASH(some_expr) SUBPARTITIONS 2
 
 Case Sensitivity and Table Reflection
 -------------------------------------