title: Dynamically query a subset of columns in sqlalchemy
body: <p>Assume only two columns(name and id) are needed from a table. I would code something like below:</p>
  
  <pre><code>session.query(User.id, User.name).all()
  </code></pre>
  
  <p>But if the column names are dynamic,</p>
  
  <pre><code>def get_data(table, columns):
      return session.query(*(getattr(table, column) for column in columns)).all()
  </code></pre>
  
  <p>But the above one looks ugly. Is there a better recommended way?</p>