How to select only some columns in SQLAlchemy?

This is my python code:

 cx=sqlalchemy.create_engine(u"mysql://username:password@ipaddress/database?charset=utf8")

 metadata=sqlalchemy.MetaData(cx)
 orm_obj=sqlalchemy.Table(u'I_POI',metadata,autoload=True)


 sql=orm_obj.select(u'poi_id,poi_name').where(u'poi_id>1 and poi_id>0').limit(3).offset(0)

 resultz=sql.execute()
 for i in resultz:
     print i

[DB] Table I_POI: poi_id, poi_name, poi_data1, poi_data2 ...... poi_data10

I am doing this with an existing database, but "select ()" does not work. It still returns the summary columns.
I want to get only a few columns, please help me.

+5
source share
1 answer

here is the code that works for me:

from sqlalchemy import select
from sqlalchemy.sql import and_

results = select([orm_obj.c.poi_id, orm_obj.c.poi_name])\
    .where(and_(orm_obj.c.id > 1, orm_obj.c.id < 100)).execute()
for id, name in results:
    print id, name
+5
source

All Articles