Re: some hints to understand the plsql cursor.

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: some hints to understand the plsql cursor.
Date: 2019-02-27 23:35:53
Message-ID: CAKU4AWpEgHKNQ2j6m5TgaGUAeM8ebx_uT5tf6vsVygKCaiZ3xw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks Kumar. actually I was asking what the the cursor did in the
server. By looking the code, looks it cache the previous Portal with the
name is the cursor name, whenever we run the fetch from the portal, it
will restore the previous Portal and run it.

But your minimized and interactive code definitely makes the debug much
quicker. Thank you very much!

On Wed, Feb 27, 2019 at 11:35 PM Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:

> On Wed, Feb 27, 2019 at 4:42 PM Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> wrote:
> >
> > actually I'm hacking pg for a function like :
> > 1. define a select query.
> > 2. client ask for some data. and server reply some data. server will do
> NOTHING if client doesn't ask any more..
> > 3. client ask some data more data with a batch and SERVER reply some
> data then. then do NOTHING.
> >
> > currently the simple "select * from t", the server will try to send the
> data to client at one time which is not something I want.
> >
> > by looking into the plsql, looks it has some api like:
> >
> > fetch 10 from cursor_1;
> > fetch 10 from cursor_1;
> >
> > I'm lacking of the experience to hack plsql. so my question are:
> > 1. Does pg has some codes which act like the "ask -> reply -> ask
> again -> reply again" on the server code? currently I'm not sure if the
> above "fetch" really work like this.
> > 2. any resources or hint or suggestion to understand the "fetch"
> statement?
>
> I guess you are looking for these syntax?
>
> postgres=# BEGIN;
> BEGIN
> postgres=# DECLARE cur CURSOR FOR SELECT * FROM t;
> DECLARE CURSOR
> postgres=# FETCH NEXT cur;
> a
> ---
> 1
> (1 row)
>
> postgres=# FETCH 10 cur;
> a
> ---
> 2
> 3
> 4
> 5
> 1
> 2
> 3
> 4
> 5
> 6
> (10 rows)
>
> postgres=# FETCH NEXT cur;
> a
> ---
> 7
> (1 row)
>
> postgres=# CLOSE cur;
> CLOSE CURSOR
>
>
> --
> Regards,
> Dilip Kumar
> EnterpriseDB: http://www.enterprisedb.com
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-02-27 23:40:30 Re: Allowing extensions to supply operator-/function-specific info
Previous Message Paul Ramsey 2019-02-27 23:11:02 Re: Allowing extensions to supply operator-/function-specific info