You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No, the refcursor type doesn't have any specific representation in psycopg.
Maybe you haven't committed the transaction where you created the sample reffunc() function?
In [1]: importpsycopg2In [2]: cnn=psycopg2.connect('')
In [3]: cur=cnn.cursor()
In [4]: cur.execute("""create function woah(refcursor) returns refcursor as $$begin open $1 for select i from generate_series(1,10) s(i); return $1;end$$ language plpgsql""")
In [5]: cur1=cnn.cursor()
In [6]: cur1.execute("select woah('hithere')")
In [7]: cur2=cnn.cursor('hithere')
In [8]: cur2.fetchone()
Out[8]: (1,)
In [9]: cur2.fetchmany(5)
Out[9]: [(2,), (3,), (4,), (5,), (6,)]
In [10]: cur2.fetchall()
Out[10]: [(7,), (8,), (9,), (10,)]
Note that the creation of the stored procedure is just a way to handle the name of the cursor as a parameter. A much simpler example is:
In [1]: importpsycopg2In [2]: cnn=psycopg2.connect('')
In [3]: cur=cnn.cursor()
In [4]: cur.execute("declare wat cursor for select i from generate_series(1,10) s(i)")
In [5]: cur2=cnn.cursor('wat')
In [6]: cur2.fetchone()
Out[6]: (1,)
I am following the very basic example in the docs for Server-side cursors and encountering the following error:
So far as I can find there is no way to translate from a python type to refcursor, not even in the extras module.
Am I missing something, or are the docs incorrect for this usage?
Thanks
The text was updated successfully, but these errors were encountered: