Please define these Python Fetch types

What is the difference between these fetching.? please give me a examples for reference site to get clear idea.still i'm confuse with it

res = cr.dictfetchall()

res2 = cr.dictfetchone()

res3 = cr.fetchall()

res4 = cr.fetchone()

as per below answers this is dictionary

[{'selected_tea_workers_line_ids': 3}, {'selected_tea_workers_line_ids': 5}]

then how to return value from that.?

    return {'value': {
                      'selected_tea_workers_line_ids':? ? ?
                      }}

refer this

cr.dictfetchall() will give you all the matching records in the form of the list of dictionary containing key, value [{'': ''}, {'': ''}, ...].

cr.dictfetchone() works same as cr.dictfetchall() except it returns only a single record {'': ''}.

cr.fetchall() will give you all the matching records in the form of the list of tuple [(''), (''), ...].

cr.fetchone() works same way as cr.fetchall() except it returns only single record ('').


In your given query, the output would be as follow:

  1. cr.dictfetchall() will give you [{'reg_no': 123},{'reg_no': 543},].
  2. cr.dictfetchone() will give you {'reg_no': 123}.
  3. cr.fetchall() will give you '[(123),(543)]'.
  4. cr.fetchone() will give you '(123)'.

Need more info?

This documentation page has been extracted from the Q&A section where you can discuss it and get feedback.
Related question