Cursors: getting the number of tuples; moving backwards

Поиск
Список
Период
Сортировка
От am@fx.ro
Тема Cursors: getting the number of tuples; moving backwards
Дата
Msg-id 20021101124348.A344@coto
обсуждение исходный текст
Ответы Re: Cursors: getting the number of tuples; moving backwards  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
Hello everyone!

I have 2 questions:

--1-- Some days ago, I've been trying to get the number of tuples
that FETCH ALL would return,  *before* fetching anything.
(the program is written in C++, using libpq ; PostgreSQL 7.2.3).

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);

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 ... ? )


--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:

  MOVE ALL in CURS    --> i get the number of tuples: 590

  MOVE -590 in CURS
  FETCH ALL           --> i get all tuples except the first one

  MOVE -591 in CURS
  FETCH ALL           --> i get all the tuples

  MOVE -1 in CURS
  FETCH ALL           --> i get nothing !

  MOVE -2 in CURS
  FETCH ALL           --> i get the last tuple

This happens only if the current position is at the end of the cursor.

Is this the normal behaviour?



Best regards,
Adrian Maier
(am@fx.ro)

В списке pgsql-general по дате отправления:

Предыдущее
От: Neil Conway
Дата:
Сообщение: Re: my.cnf to postgresql.conf Conversion
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Cursors: getting the number of tuples; moving backwards