From: | am(at)fx(dot)ro |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Cursors: getting the number of tuples; moving backwards |
Date: | 2002-11-01 18:14:33 |
Message-ID: | 20021101201433.A568@coto |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers pgsql-jdbc |
On Fri, Nov 01, 2002 at 07:23:29PM +1100, Martijn van Oosterhout wrote:
> > The solution i've found was something like:
> >
> > int nr_tuples;
> >
> > res = PQexec(conn, "MOVE ALL in CURS");
> > sscanf(PQcmdStatus(res),"MOVE %i",&nr_tuples);
> > PQclear(res);
>
> That would work. But why do you need to know the total beforehand? You could
> just do a FETCH ALL and then use PQntuples to get the number.
If the table has, let's say, 10000 rows, it's unlikely that the user
will ever browse all of them ( my program permits the user to set some
filters ; the interface is ncurses-based). Fetching everything
would be unnecessary.
So, for speed reasons, i prefer to fetch maximum 500 rows.
But i want to display in the screen's corner the total number
of rows .
> > I'm wondering: is there any better way to get that number?
> >
> > ( just an idea: maybe it would be useful to make PQcmdTuples
> > work for MOVE commands ... ? )
>
> Interesting idea. I'm not sure whether MOVE actually executes the query or
> not.
I guess it doesn't execute the whole query. MOVE ALL is *much*
faster than FETCH ALL + PQcmdTuples
> > --2-- I found out that if i reach the end of the cursor, and want
> > to move backwards, i have to increase the MOVE command's argument by 1:
>
> No idea, the cursor has probably moved off the end to indicate the query is
> done. So you need the extra one to move it back. That's just a guess though.
Yeah, this could be the explanation.
Thanks for your answer
Adrian Maier
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2002-11-01 18:18:13 | Re: Questions on specifying table relationships |
Previous Message | Tyrone | 2002-11-01 17:42:45 | computational question |
From | Date | Subject | |
---|---|---|---|
Next Message | Ulrich Neumann | 2002-11-01 18:15:58 | Antw: Re: Some questions about the NetWare Port - please comment |
Previous Message | Tom Lane | 2002-11-01 17:36:23 | Re: Some questions about the NetWare Port - please comment |
From | Date | Subject | |
---|---|---|---|
Next Message | Dror Matalon | 2002-11-01 18:40:16 | Importing data into the database using JDBC |
Previous Message | am | 2002-11-01 10:43:48 | Cursors: getting the number of tuples; moving backwards |