]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Clean-up implementation 12584/head
authorThomas Stephenson <ovangle@gmail.com>
Fri, 16 May 2025 15:51:07 +0000 (01:51 +1000)
committerThomas Stephenson <ovangle@gmail.com>
Fri, 16 May 2025 15:52:59 +0000 (01:52 +1000)
- Add pg_tablespace, pg_inherits tables to pg_catalog (not committed
  originally)
- Add test for table using non-default access method
- Remove commented code
- Correct formatting errors in docs

lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/postgresql/pg_catalog.py
test/dialect/postgresql/test_reflection.py

index 1e800215e9e8dbb44b1cc192907bf09c2fd932e0..12600ff831af79dbf0f633f4fa1760b3afeffd5a 100644 (file)
@@ -1206,14 +1206,14 @@ dialect in conjunction with the :class:`_schema.Table` construct:
 
     Table("some_table", metadata, ..., postgresql_with={"fillfactor": 100})
 
   Set various storage options on the table
+ Set various storage options on the table
 
 * ``WITH OIDS``::
 
     Table("some_table", metadata, ..., postgresql_with_oids=True)
 
-    Automatically add object identifiers to table rows. Legacy feature, removed
-    in postgresql 12.
+Automatically add object identifiers to table rows. Removed
+in postgresql 12.
 
 * ``WITHOUT OIDS``::
 
index 4841056cf9d1660a47c074906c6a71a7d5afecde..69633c4ef8514e5a35853b7907af7a198c5113ce 100644 (file)
@@ -310,3 +310,22 @@ pg_collation = Table(
     Column("collicurules", Text, info={"server_version": (16,)}),
     Column("collversion", Text, info={"server_version": (10,)}),
 )
+
+pg_inherits = Table(
+    "pg_inherits",
+    pg_catalog_meta,
+    Column("inhrelid", OID),
+    Column("inhparent", OID),
+    Column("inhseqno", Integer),
+    Column("inhdetachpending", Boolean),
+)
+
+pg_tablespace = Table(
+    "pg_tablespace",
+    pg_catalog_meta,
+    Column("oid", OID),
+    Column("spcname", NAME),
+    Column("spcowner", OID),
+    Column("spcacl", ARRAY(Text)),
+    Column("spcoptions", ARRAY(Text)),
+)
index 3c3794bbb2e584c10caaa4b12c6cd254de312fad..3d1436f6b74c32537e1b3ed7a3b0710f9b66c5a6 100644 (file)
@@ -2930,6 +2930,16 @@ class TestTableOptionsReflection(fixtures.TestBase):
     __only_on__ = "postgresql"
     __backend__ = True
 
+    def setupTests(self, connection):
+        connection.exec_driver_sql(
+            "CREATE ACCESS METHOD myaccessmethod "
+            "TYPE TABLE "
+            "HANDLER heap_tableam_handler"
+        )
+
+    def teardownTests(self, connection):
+        connection.exec_driver_sql("DROP ACCESS METHOD myaccessmethod")
+
     def test_table_inherits(self, metadata, connection):
         def assert_inherits_from(table_name, expect_base_tables):
             table_options = inspect(connection).get_table_options(table_name)
@@ -2991,49 +3001,33 @@ class TestTableOptionsReflection(fixtures.TestBase):
         no_params_options = inspect(connection).get_table_options(
             "table_no_storage_params"
         )
-        assert "postgresql_with" in no_params_options
+        assert "postgresql_with" not in no_params_options
 
         assert_has_storage_param("table_with_fillfactor", "fillfactor", "10")
         assert_has_storage_param(
             "table_with_parallel_workers", "parallel_workers", "15"
         )
 
-    # @testing.skip_if("postgresql >= 12.0", "with_oids not supported")
-    # def test_table_with_oids(self, metadata, connection):
-    #     Table("table_with_oids", metadata, postgresql_with_oids=True)
-    #     Table("table_without_oids", metadata, postgresql_with_oids=False)
-    #     metadata.create_all(connection)
-
-    #     table_options = inspect(connection).get_table_options("table_with_oids")
-    #     eq_(table_options["postgresql_with_oids"], True)
-
-    #     table_options = inspect(connection).get_table_options("table_without_oids")
-    #     eq_(table_options["postgresql_with_oids"], False)
-
-    def test_table_using(self, metadata, connection):
+    def test_table_using(self, metadata: MetaData, connection):
         Table("table_using_heap", metadata, postgresql_using="heap")
-        Table("heap_is_default", metadata)
+        Table(
+            "table_using_myaccessmethod",
+            metadata,
+            postgresql_using="myaccessmethod",
+        )
         metadata.create_all(connection)
 
-        table_options = inspect(connection).get_table_options(
+        table_using_heap_options = inspect(connection).get_table_options(
             "table_using_heap"
         )
-        print("table_options", table_options)
-        eq_(table_options["postgresql_using"], "heap")
+        eq_(table_using_heap_options["postgresql_using"], "heap")
 
-        table_options = inspect(connection).get_table_options(
-            "heap_is_default"
+        table_using_myaccessmethod_options = inspect(
+            connection
+        ).get_table_options("table_using_myaccessmethod")
+        eq_(
+            table_using_myaccessmethod_options["postgresql_using"],
+            "myaccessmethod",
         )
-        eq_(table_options["postgresql_using"], "heap")
-
-        # TODO: Test custom access method.
-
-        # self.define_table(metadata, "table_using_btree", postgresql_using="btree")
-        # table_options = inspect(connection).get_table_options("table_using_btree")
-        # eq_(table_options["using"], "btree")
-
-    # def test_table_option_tablespace(self, metadata, connection):
-    #     self.define_simple_table(metadata, "table_sample_tablespace", postgresql_tablespace="sample_tablespace")
 
-    #     table_options = inspect(connection).get_table_options("table_sample_tablespace")
-    #     eq_(table_options["tablespace"], "sample_tablespace")
+        metadata.drop_all(connection)