number of records returned by cursors

Поиск
Список
Период
Сортировка
От Zac
Тема number of records returned by cursors
Дата
Msg-id d9ojvj$27mm$1@news.hub.org
обсуждение исходный текст
Ответы Re: number of records returned by cursors  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hi,
does anyone know if there is a way (in plpgsql) to obtain the number of
records returned by a cursor without fetching them all?

Using "FOUND" and "GET DIAGNOSTICS row_count" variables doesn't help me:
the only way seems to be fetching all the records.

I try to explain it better:

CREATE OR REPLACE FUNCTION test_cur() RETURNS void AS
$$
DECLARE
         c CURSOR FOR SELECT 'foo' UNION SELECT 'bar';
         i integer;
         t text;
BEGIN
         OPEN c;
         RAISE INFO 'FOUND: %', FOUND;
         GET DIAGNOSTICS i = row_count;
         RAISE INFO 'row_count: %', i;

         FETCH c INTO t;
         RAISE INFO '1 row (of 2) fetched: %', t;
         RAISE INFO 'FOUND: %', FOUND;
         GET DIAGNOSTICS i = row_count;
         RAISE INFO 'row_count: %', i;

         FETCH c INTO t;
         RAISE INFO '2 row (of 2) fetched: %', t;
         RAISE INFO 'FOUND: %', FOUND;
         GET DIAGNOSTICS i = row_count;
         RAISE INFO 'row_count: %', i;

         CLOSE c;
END;
$$ LANGUAGE plpgsql;

SELECT test_cur();
INFO:  FOUND: f
INFO:  row_count: 0
INFO:  1 row (of 2) fetched: bar
INFO:  FOUND: t
INFO:  row_count: 0
INFO:  2 row (of 2) fetched: foo
INFO:  FOUND: t
INFO:  row_count: 0
  test_cur
----------

(1 row)


Thank you.
Zac

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

Предыдущее
От: Milorad Poluga
Дата:
Сообщение: Re: How to compare the schemas ?
Следующее
От: Andreas
Дата:
Сообщение: Re: automating backup ?