My SQLAlchemy code:
used_emails = list(db.execute(halo4.select(halo4.c.email != '')))
returns:
[(80940L, 'P7J4H-DFDMG-G6HMJ-W7PF9-MDTF1', '1', 'first.last@domain.com', datetime.datetime(2012, 11, 3, 3, 48, 58)), (80939L, 'GCTFY-QPK2Y-PX1CJ-W69QY-PHDGZ', '1', 'first.last@domain.com', datetime.datetime(2012, 11, 3, 15, 8, 15)), (80938L, 'R4XGV-PG461-RGXX7-9R47R-2RWYZ', '1', 'first.last@domain.com', datetime.datetime(2012, 11, 3, 15, 8, 27))]
How do I make SQLAlchemy only return:
[('first.last@domain.com', 'first.last@domain.com', 'first.last@domain.com')]
The following will give a list of the
emailcolumn values:Basically you are telling the
select()function to generate aSELECTstatement for just theemailcolumn. The result ofexecute()will be aResultProxyso the job of the list comprehension is to create a list ofemailcolumn string values from the single column rows obtained from the iterableResultProxy.