Skip to content

Commit f6917ec

Browse files
committed
Fix #951 inconsistent length of QueryExpression
1 parent 7764467 commit f6917ec

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

datajoint/expression.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ def tail(self, limit=25, **fetch_kwargs):
439439

440440
def __len__(self):
441441
""":return: number of elements in the result set e.g. ``len(q1)``."""
442+
try:
443+
if self._left[0]:
444+
return self.connection.query(
445+
'SELECT distinct count(*) FROM {from_}{where}'.format(
446+
from_=self.from_clause(),
447+
where=self.where_clause())).fetchone()[0]
448+
except IndexError:
449+
pass
442450
return self.connection.query(
443451
'SELECT count(DISTINCT {fields}) FROM {from_}{where}'.format(
444452
fields=self.heading.as_sql(self.primary_key, include_aliases=False),

0 commit comments

Comments
 (0)