fixed up some of the error messages tailored
in [ticket:2069]
+ - query.count() emits "count(*)" instead of
+ "count(1)". [ticket:2162]
+
- Fine tuning of Query clause adaptation when
from_self(), union(), or other "select from
myself" operation, such that plain SQL expression
session.query(func.count(distinct(User.name)))
"""
- col = sql.func.count(sql.literal_column('1'))
+ col = sql.func.count(sql.literal_column('*'))
return self.from_self(col).scalar()
def delete(self, synchronize_session='evaluate'):
from sqlalchemy.engine import default
from sqlalchemy.orm import *
from sqlalchemy.orm import attributes
-
+from test.lib.assertsql import CompiledSQL
from test.lib.testing import eq_
import sqlalchemy as sa
eq_(s.query(User).filter(users.c.name.endswith('ed')).count(), 2)
+ def test_count_char(self):
+ User = self.classes.User
+ s = create_session()
+ # '*' is favored here as the most common character,
+ # it is reported that Informix doesn't like count(1),
+ # rumors about Oracle preferring count(1) don't appear
+ # to be well founded.
+ self.assert_sql_execution(
+ testing.db,
+ s.query(User).count,
+ CompiledSQL(
+ "SELECT count(*) AS count_1 FROM "
+ "(SELECT users.id AS users_id, users.name "
+ "AS users_name FROM users) AS anon_1",
+ {}
+ )
+ )
+
def test_multiple_entity(self):
User, Address = self.classes.User, self.classes.Address