title: SQLAlchemy Reflection: How do I query data from specific columns?
body: <p>Using SQLAlchemy reflection, how do I query for data in specific column?</p>
  
  <pre><code>testtable = Table('member', Metadata, autoload=True)
  
  def TestConnection():
      data = None
      loopCounter = 0 
      for data in session.query(testtable).filter_by(is_active=1, is_deleted=0): 
          print(loopCounter + 1, data)
          loopCounter += 1
      if data is None:
          raise Exception ("Could not find any data that matches your query")        
      else:
          print("It worked!")
  
  TestConnection()
  </code></pre>
  
  <p>The above query gives me all the data in all columns in the <strong>members</strong> table. What I want however is to get specific data from columns. E.g. I want to retrieve the <strong>username</strong> and <strong>password</strong> columns but I just can't get the syntax right. Below is what I have so far:</p>
  
  <pre><code>def TestConnection():
      loopCounter = 0 
      for password, username in session.query(testtable).filter_by(is_active=1, is_deleted=0):
          print(loopCounter + 1, data)
          loopCounter += 1
      if data is None:
          raise Exception ("Could not find any data that matches your query")        
      else:
          print("It worked!")
  </code></pre>
  
  <p>That fails with the error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "/home/workspace/upark/src/monitor.py", line 36, in &lt;module&gt;
  TestConnection()
  File "/home/workspace/upark/src/monitor.py", line 26, in TestConnection
  for password, username in session.query(testtable).filter_by(is_active=1, is_deleted=0):
  ValueError: too many values to unpack (expected 2)
  </code></pre>
  
  <p>Am working with Python3.2, SQLAchemy0.8 and mysqlconnector from Oracle.</p>
  
  <p><strong>EDIT: some slight progress</strong></p>
  
  <p>Just discovered that I can "filter" out the columns after all results have been returned as follows:</p>
  
  <pre><code>def TestConnection():
      data = None
      loopCounter = 0 
      for data in session.query(testtable).filter_by(is_active=1, is_deleted=0): 
          print(loopCounter + 1, data.password, data.username)
          loopCounter += 1
      if data is None:
          raise Exception ("Could not find any data that matches your query")        
      else:
          print("It worked!")
  </code></pre>
  
  <p>That will give:</p>
  
  <pre><code>1 pass1 userone
  2 pass2 usertwo
  </code></pre>
  
  <p>But as you can see, that is after I've gotten all the columns back. What I want is to fetch data from only the columns I need. E.g. The Members table has got 10 columns. I only need to get data from two of those for efficiency.</p>