Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

get first row sqlalchemy

result = session.query(profile.name).filter(...).first()
if not result:
    print 'No result found'
# Alternatively you can use one(), which will give you the only item, 
# but raise exceptions for a query with zero or multiple results
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.orm.exc import MultipleResultsFound

try:
    user = session.query(User).one()
except MultipleResultsFound, e:
    print e
    # Deal with it
except NoResultFound, e:
    print e
    # Deal with that as well
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #row #sqlalchemy
ADD COMMENT
Topic
Name
4+4 =