Skip to content

Instantly share code, notes, and snippets.

@camelcaseblog
Last active February 6, 2019 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camelcaseblog/47c4c72e6f40eaad14a2a1252fe74610 to your computer and use it in GitHub Desktop.
Save camelcaseblog/47c4c72e6f40eaad14a2a1252fe74610 to your computer and use it in GitHub Desktop.
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