title: Memory efficient way of fetching postgresql uniqueue dates?
body: <p>I have a database with roughly 30 million entries, which is a lot and i don't expect anything but trouble working with larger database entries.</p>
  
  <p>But using py-postgresql and the <code>.prepare()</code> statement i would hope i could fetch entries on a "<code>yield</code>" basis and thus avoiding filling up my memory with only the results from the database, which i aparently can't?</p>
  
  <p>This is what i've got so far:</p>
  
  <pre><code>import postgresql
  user = 'test'
  passwd = 'test
  db = postgresql.open('pq://'+user+':'+passwd+'@192.168.1.1/mydb')
  results = db.prepare("SELECT time time FROM mytable")
  uniqueue_days = []
  with db.xact():
      for row in result():
          if not row['time'] in uniqueue_days:
              uniqueue_days.append(row['time'])
  
  print(uniqueue_days)
  </code></pre>
  
  <p>Before even getting to <code>if not row['time'] in uniqueue_days:</code> i run out of memory, which isn't so strange considering <code>result()</code> probably fetches all results befor looping through them?
  Is there a way to get the library <code>postgresql</code> to "page" or batch down the results in say a 60k per round or perhaps even rework the query to do more of the work?</p>
  
  <p>Thanks in advance!</p>
  
  <p>Edit: Should mention the dates in the database is Unix timestamps, and i intend to convert them into <code>%Y-%m-%d</code> format prior to adding them into the <code>uniqueue_days</code> list.</p>