On Wed, Apr 5, 2017 at 11:10 AM, Mayank Soni <mayank.so...@gmail.com> wrote: > I am trying to pass list of columns of table into query method using > add_columns method. Below i am mentioning code snipped. > > def LLL(): > Base = automap_base() > class AAA(Base): > __tablename__ = 'schools_master' > Base.prepare(engine, reflect=True) > session = sessionmaker(bind=engine) > session = session() > col_name = > ['dise_code_01','district_name_02','block_name_03','cluster_name_04','village_name_05'] > > q = session.query(AAA).add_columns(col_list) > > q = q.limit(100) > > for row in q: > print(row) > > When i execute this code it is generating error massage : > massage.sqlalchemy.exc.InvalidRequestError: SQL expression, column, or > mapped entity expected - got '['dise_code_01', 'district_name_02', > 'block_name_03', 'cluster_name_04', 'village_name_05'] > > Please help me out from this error. >
add_columns expects each column to be supplied as a separate argument, so you at least need: q = session.query(AAA).add_columns(*col_list) ...to unpack the list. Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.