]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Merge "Add TABLESAMPLE clause support."
authormike bayer <mike_mp@zzzcomputing.com>
Wed, 15 Jun 2016 19:17:10 +0000 (15:17 -0400)
committerGerrit Code Review <gerrit2@ln3.zzzcomputing.com>
Wed, 15 Jun 2016 19:17:10 +0000 (15:17 -0400)
1  2 
doc/build/core/selectable.rst
lib/sqlalchemy/sql/selectable.py

Simple merge
index 741aa9beadc88f2c3a118c735024298eed737168,e62aa1e8e9f673a66d16972d518a194193b57df4..9770b11bbfd77e16d3e3f86c5d147901f639f0b5
@@@ -180,9 -180,54 +180,54 @@@ def lateral(selectable, name=None)
          :ref:`lateral_selects` -  overview of usage.
  
      """
 -    return selectable.lateral(name=name)
 +    return _interpret_as_from(selectable).lateral(name=name)
  
  
+ def tablesample(selectable, sampling, name=None, seed=None):
+     """Return a :class:`.TableSample` object.
+     :class:`.TableSample` is an :class:`.Alias` subclass that represents
+     a table with the TABLESAMPLE clause applied to it.
+     :func:`~.expression.tablesample`
+     is also available from the :class:`.FromClause` class via the
+     :meth:`.FromClause.tablesample` method.
+     The TABLESAMPLE clause allows selecting a randomly selected approximate
+     percentage of rows from a table. It supports multiple sampling methods,
+     most commonly BERNOULLI and SYSTEM.
+     e.g.::
+         from sqlalchemy import func
+         selectable = people.tablesample(
+                     func.bernoulli(1),
+                     name='alias',
+                     seed=func.random())
+         stmt = select([selectable.c.people_id])
+     Assuming ``people`` with a column ``people_id``, the above
+     statement would render as::
+         SELECT alias.people_id FROM
+         people AS alias TABLESAMPLE bernoulli(:bernoulli_1)
+         REPEATABLE (random())
+     .. versionadded:: 1.1
+     :param sampling: a ``float`` percentage between 0 and 100 or
+         :class:`.functions.Function`.
+     :param name: optional alias name
+     :param seed: any real-valued SQL expression.  When specified, the
+      REPEATABLE sub-clause is also rendered.
+     """
+     return _interpret_as_from(selectable).tablesample(
+         sampling, name=name, seed=seed)
  class Selectable(ClauseElement):
      """mark a class as being selectable"""
      __visit_name__ = 'selectable'