]> 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:40:44 +0000 (17:40 +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

lib/sqlalchemy/dialects/postgresql/base.py

index e529f15b91e49a0dd043bef30ec77fc178cc93cb..eb59d845a7e5ec0f7793f05d9ba024c4f6a4316d 100644 (file)
@@ -1251,6 +1251,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``
 ^^^^^^^^^^^^^