]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
represent tablesample.sampling as FunctionElement in all cases
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Jul 2021 23:40:59 +0000 (19:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Jul 2021 23:40:59 +0000 (19:40 -0400)
Fixed regression where the :func:`_sql.tablesample` construct would fail to
be executable when constructed given a floating-point sampling value not
embedded within a SQL function.

Fixes: #6735
Change-Id: I557bcd4bdbffc4329ad69d5659ba99b1c8deb554

doc/build/changelog/unreleased_14/6735.rst [new file with mode: 0644]
lib/sqlalchemy/sql/selectable.py
test/sql/test_compare.py

diff --git a/doc/build/changelog/unreleased_14/6735.rst b/doc/build/changelog/unreleased_14/6735.rst
new file mode 100644 (file)
index 0000000..9e8a3f2
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, sql, regression
+    :tickets: 6735
+
+    Fixed regression where the :func:`_sql.tablesample` construct would fail to
+    be executable when constructed given a floating-point sampling value not
+    embedded within a SQL function.
index 235c74ea76d7a5d1d93056243034ec7b75dd5b25..42cb6e5aefb96501d44913a53dcd2de1de137155 100644 (file)
@@ -1970,18 +1970,18 @@ class TableSample(AliasedReturnsRows):
             sampling, name=name, seed=seed
         )
 
+    @util.preload_module("sqlalchemy.sql.functions")
     def _init(self, selectable, sampling, name=None, seed=None):
+        functions = util.preloaded.sql_functions
+        if not isinstance(sampling, functions.Function):
+            sampling = functions.func.system(sampling)
+
         self.sampling = sampling
         self.seed = seed
         super(TableSample, self)._init(selectable, name=name)
 
-    @util.preload_module("sqlalchemy.sql.functions")
     def _get_method(self):
-        functions = util.preloaded.sql_functions
-        if isinstance(self.sampling, functions.Function):
-            return self.sampling
-        else:
-            return functions.func.system(self.sampling)
+        return self.sampling
 
 
 class CTE(
index e96a47553b17d47ab36ac57abe555653e4d6c94b..365ed52b2aa3da3274f55177b247ded255887aca 100644 (file)
@@ -504,6 +504,7 @@ class CoreFixtures(object):
             .union_all(select(table_a.c.b)),
             select(table_a.c.a).lateral(),
             select(table_a.c.a).lateral(name="bar"),
+            table_a.tablesample(0.75),
             table_a.tablesample(func.bernoulli(1)),
             table_a.tablesample(func.bernoulli(1), seed=func.random()),
             table_a.tablesample(func.bernoulli(1), seed=func.other_random()),