]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Improve postgresql inherits docs
authorFederico Caselli <cfederico87@gmail.com>
Tue, 28 Jul 2026 18:18:40 +0000 (20:18 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 3 Aug 2026 17:42:03 +0000 (17:42 +0000)
Clarify that inherited table columns are not copied by default
and provide an example of a function that will copy them.

Change-Id: I17811c1d3500fbb22a015226325004c1d7ade0c6
References: #13446
(cherry picked from commit 102532a2a1473140705de0296915e571eda14961)

lib/sqlalchemy/dialects/postgresql/base.py

index 92efcd5a1d1e03b984d73fd952f172396bcb4dce..64b702946b68bf600d0632ff23566785997e64e3 100644 (file)
@@ -1213,6 +1213,33 @@ identifier::
         ),
     )
 
+SQLAlchemy does not automatically copy the columns from the inherited tables
+mentioned in the ``postgresql_inherits`` argument into the new
+:class:`_schema.Table`. To populate the new table columns reflection may be
+used, or a function similar to the following one::
+
+    def get_parent_columns(tbl: sa.Table) -> list[sa.Column]:
+        return [
+            sa.Column(
+                c.name,
+                c.type,
+                key=c.key,
+                nullable=c.nullable,
+                # Set system=true to omit from the CREATE TABLE statement
+                system=True,
+            )
+            for c in tbl.columns
+        ]
+
+
+    documents = Table(
+        "some_table",
+        metadata,
+        *get_parent_columns(some_supertable),
+        # ... # add other columns here normally if needed
+        postgresql_inherits="some_supertable",
+    )
+
 ``ON COMMIT``
 ^^^^^^^^^^^^^