summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_reflection.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-10-01 16:23:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-10-01 16:24:55 -0400
commitf1ca155cea10e32fec3dfe9fdae6674ee81c0ef4 (patch)
treebe3985ecd220d43724654991aa1c0b46a7c9f3e7 /test/dialect/postgresql/test_reflection.py
parent29d54ab69b689c2bc4b9be8273f4c0a96e37153f (diff)
downloadsqlalchemy-f1ca155cea10e32fec3dfe9fdae6674ee81c0ef4.tar.gz
Add reflection support for Postgresql partitioned tables
Added rudimental support for reflection of Postgresql partitioned tables, e.g. that relkind='p' is added to reflection queries that return table information. Fixes: #4237 Change-Id: I66fd10b002e4ed21ea13b13a7e35a85f66bdea75
Diffstat (limited to 'test/dialect/postgresql/test_reflection.py')
-rw-r--r--test/dialect/postgresql/test_reflection.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py
index 70bc26e0b..b30cb506b 100644
--- a/test/dialect/postgresql/test_reflection.py
+++ b/test/dialect/postgresql/test_reflection.py
@@ -74,6 +74,51 @@ class ForeignTableReflectionTest(fixtures.TablesTest, AssertsExecutionResults):
eq_(names, ['testtable'])
+class PartitionedReflectionTest(
+ fixtures.TablesTest, AssertsExecutionResults):
+ # partitioned table reflection, issue #4237
+
+ __only_on__ = 'postgresql >= 10'
+ __backend__ = True
+
+ @classmethod
+ def define_tables(cls, metadata):
+ # the actual function isn't reflected yet
+ dv = Table(
+ 'data_values', metadata,
+ Column('modulus', Integer, nullable=False),
+ Column('data', String(30)),
+ postgresql_partition_by='range(modulus)')
+
+ # looks like this is reflected prior to #4237
+ sa.event.listen(
+ dv,
+ "after_create",
+ sa.DDL(
+ "CREATE TABLE data_values_4_10 PARTITION OF data_values "
+ "FOR VALUES FROM (4) TO (10)")
+ )
+
+ def test_get_tablenames(self):
+ assert {'data_values', 'data_values_4_10'}.issubset(
+ inspect(testing.db).get_table_names()
+ )
+
+ def test_reflect_cols(self):
+ cols = inspect(testing.db).get_columns('data_values')
+ eq_(
+ [c['name'] for c in cols],
+ ['modulus', 'data']
+ )
+
+ def test_reflect_cols_from_partition(self):
+ cols = inspect(testing.db).get_columns('data_values_4_10')
+ eq_(
+ [c['name'] for c in cols],
+ ['modulus', 'data']
+ )
+
+
class MaterializedViewReflectionTest(
fixtures.TablesTest, AssertsExecutionResults):
"""Test reflection on materialized views"""