python
Replace NULL with false while Selecting in SQLAlchemy
Here we are replacing active column value of user table with false if it is null
from sqlalchemy import func
# SYNTAX - func.coalesce(model.prop, default_value)
db.session.query(
UserModel.id,
func.coalesce(UserModel.active, false).label('is_active'),
).filter(
UserModel.status == 'active'
).all()
Was this helpful?
Similar Posts
- Filter based on NULL Values in SQLAlchemy
- While loop python
- Python code to remove falsy values(None, False, [], {}, etc)
- Check for falsy values - None, False, blank in Python
- Python - regex , replace multiple spaces with one space
- Python - regex,replace all character exept A-Z a-z and numbers
- Python - regex , remove all single characters,replace all single chars,char