Re: Stored procedures returning cursors

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Rodolfo Stangherlin <RStanghe(at)ucs(dot)br>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Stored procedures returning cursors
Date: 2011-12-20 19:26:49
Message-ID: CA+mi_8YgDWTieGYJ2LmNLNkEZD4MsoO5gUHyKmmREhuFhDrfAg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Tue, Dec 20, 2011 at 6:47 PM, Rodolfo Stangherlin <RStanghe(at)ucs(dot)br> wrote:
> I was trying to call a procedure returning a "ref cursor" in a PostgreSQL
> database. It works with psycopg2 2.3.2, but not with 2.4.4.
>
> My code looks like this:
> http://osdir.com/ml/python.db.psycopg.devel/2005-10/msg00116.html
>
> The result is a "cursor <unnamed portal 1> doesn't exists"
> How I can do it in the right way?

You should give a name to the portal to make it work.

The example still works (I had to omit the quotes decorating the name
in Portal.__init__) but there is an easier technique to obtain the
same result: execute the function creating the (named) ref cursor,
then just create a named cursor to steal it. It has been discussed
recently in this list and there is an example in the documentation:
see <http://initd.org/psycopg/docs/usage.html#server-side-cursors> (in
the note box).

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Christopher David Howie 2011-12-21 19:13:28 Rows from a stored procedure result are stringified
Previous Message Rodolfo Stangherlin 2011-12-20 18:47:37 Stored procedures returning cursors