title: Querying multiple columns efficiently SQLAlchemy ORM
body: <p>I am trying to do a query using SQL Alchemy, but I want to "select" 20 columns from a table that contains around 57, I know that the method to do this is </p>
  
  <pre><code>session.query(Table.col1, Table.col2, Table.col3, Table.col4......).all()
  
  </code></pre>
  
  <p>But it is so inefficient and for sure there is a much better way for doing this.</p>
  
  <p>What I have tried unsuccessfully, but it is getting very close is:</p>
  
  <pre><code># "columns" is a dictionary that contains all the column names, it looks more or less like this (shorter version
  
  columns = {"Account ID": "AR3",
           "Account Origination Month": "AR55",
           "Origination balance": "AR66",
           "Product": "AR10",
           "Repayment Type": "AR69",
           "Original Loan Term (in months)": "AR61",
           "Initial Product Term (in months)": "AR106",
           "Initial rate/margin": "AR109",
           "Initial Rate Type": "AR107",
           "Reversion margin": "AR119",}
  
  
  
  columns_sqla = ", ".join(["Table."+str(value) for key, value in columns.items()])
  
  &gt;&gt;&gt; columns_sqla
  
  'BoE.AR3, BoE.AR55, BoE.AR66, BoE.AR10, BoE.AR69, BoE.AR61, BoE.AR106, BoE.AR109, BoE.AR107, BoE.AR119'
  
  </code></pre>
  
  <p>Then I do:</p>
  
  <pre><code>session.query(columns_sqla)
  
  </code></pre>
  
  <p>But it throws an error because it is a string and it doesn't recognise it.</p>