Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

My code returns all 80999 results. I only want one. Whats the best way to do this?

This a sample of code.db:

(u'JRQRY-MYHW3-D67GR-7YWFF-CRJ31', None)
(u'9D7DR-4WFDY-VG49F-3DYCG-7DYT5', None)
(u'QR9WT-P3CTM-PW4WW-34JJ4-RFKV7', None)
(u'7FMXQ-H97TC-FFYC6-XHXFV-Y7KR2', None)
(u'VKHXW-29WC4-4PF4Y-2QMJ4-4W2H4', None)
                Any of them really. I'm already returning all rows with status of None. I just need one row returned vs all rows.
– David Vasandani
                Nov 3, 2012 at 1:43
                It's hard to try this without your data. But SqlAlchemy maps index access to limits, so you should be able to do result[0].
– Keith
                Nov 3, 2012 at 1:52

If you want to get just one row from a ResultProxy object (which is the result of your s.execute() statement, you need to use the fetchone() method:

s = select([halo4.c.code, halo4.c.status=='None'])
result = s.execute()
one_row = result.fetchone()
another_row = result.fetchone()
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.