question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using func.sum(BinaryExp), returns a boolean instead of a sum (wasn't the case in 1.1.12)

See original GitHub issue

Migrated issue, originally created by Bastien Gérard (@bagerard)

Hi, First of all, we are using MySQL 5.6

After switching from sqlalchemy 1.1.12 to 1.2.2, we observed that one of our test failed.

In fact the following scenario should return a RowProxy with the values being the sum but the values are boolean instead.

from sqlalchemy import select
from sqlalchemy.sql.functions import func

engine, tbl, col = ...
sel = select([func.sum(col.is_(None))])
print sel # SELECT sum(smart_result.signal_predicted IS NULL) AS sum_1 FROM smart_result
row = engine.execute(sel).fetchone()
print dict(row) # {u'sum_1': True}

# And if I execute it manually:
r = engine.execute('SELECT sum(smart_result.signal_predicted IS NULL) AS sum_1 FROM smart_result')
print r.fetchall() # [(Decimal('120'),)]

I don’t know if it could be related but by printing row._key_map, I see references to “<function sqlalchemy.cprocessors.int_to_boolean>”.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
sqlalchemy-botcommented, Nov 27, 2018

Bastien Gérard (@bagerard) wrote:

As a workaround, note that the following works:

sel = select([func.sum(v.is_(None)).cast(Integer)])
row = engine.execute(sel).fetchone()

print dict(row) # {u'anon_1': 120L}
0reactions
sqlalchemy-botcommented, Nov 27, 2018

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sqlalchemy sum of true - Stack Overflow
I thought about nullable(boolean) ( boolean column without default value). WHERE value2 != TRUE and WHERE value2 IS NOT TRUE . In any...
Read more >
Solved: sum case expression returning boolean values
Re: sum case expression returning boolean values​​ Please provide details on which value, MS1 or MS2, should be returned. Your current code or ......
Read more >
Game Theory, Alive
Proof of Theorem 1.1.12. Define Z to be those positions with Nim-sum zero. We will show that: (a) From every position in Z,...
Read more >
powerful Python data analysis toolkit - Pandas
When converting a dataframe to HTML it used to return Empty DataFrame. This special case has been removed, instead a header with the...
Read more >
micropython-docs.pdf
This chapter describes modules (function and class libraries) which are built into MicroPython. This documentation in general aspires to describe all ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found