summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/selectable.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
-rw-r--r--lib/sqlalchemy/sql/selectable.py41
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index f75613e35..ac955a60f 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -308,10 +308,34 @@ class FromClause(Selectable):
_memoized_property = util.group_expirable_memoized_property(["_columns"])
+ @util.deprecated(
+ '1.1',
+ message="``FromClause.count()`` is deprecated. Counting "
+ "rows requires that the correct column expression and "
+ "accommodations for joins, DISTINCT, etc. must be made, "
+ "otherwise results may not be what's expected. "
+ "Please use an appropriate ``func.count()`` expression "
+ "directly.")
@util.dependencies("sqlalchemy.sql.functions")
def count(self, functions, whereclause=None, **params):
"""return a SELECT COUNT generated against this
- :class:`.FromClause`."""
+ :class:`.FromClause`.
+
+ The function generates COUNT against the
+ first column in the primary key of the table, or against
+ the first column in the table overall. Explicit use of
+ ``func.count()`` should be preferred::
+
+ row_count = conn.scalar(
+ select([func.count('*')]).select_from(table)
+ )
+
+
+ .. seealso::
+
+ :data:`.func`
+
+ """
if self.primary_key:
col = list(self.primary_key)[0]
@@ -1610,21 +1634,6 @@ class TableClause(Immutable, FromClause):
else:
return []
- @util.dependencies("sqlalchemy.sql.functions")
- def count(self, functions, whereclause=None, **params):
- """return a SELECT COUNT generated against this
- :class:`.TableClause`."""
-
- if self.primary_key:
- col = list(self.primary_key)[0]
- else:
- col = list(self.columns)[0]
- return Select(
- [functions.func.count(col).label('tbl_row_count')],
- whereclause,
- from_obj=[self],
- **params)
-
@util.dependencies("sqlalchemy.sql.dml")
def insert(self, dml, values=None, inline=False, **kwargs):
"""Generate an :func:`.insert` construct against this