Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
print(session.query(User).filter(User.name is None)) # 1
'''
SELECT users.id AS users_id, users.name AS users_name
FROM users
WHERE 0 = 1
'''
print(session.query(User).filter(User.name.is_(None))) # 2
'''
SELECT users.id AS users_id, users.name AS users_name
FROM users
WHERE users.name IS NULL
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment