pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
how many tuples on a cursor?
4+ messages / 3 participants
[nested] [flat]

* how many tuples on a cursor?
@ 2005-05-02 07:13 Andreas Kretschmer <akretschmer@despammed.com>
  2005-05-02 11:17 ` Re: how many tuples on a cursor? Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 1 reply; 4+ messages in thread

From: Andreas Kretschmer @ 2005-05-02 07:13 UTC (permalink / raw)
  To: pgsql-sql

Hello,

I want to know how many tuples there on a cursor, and i found
http://groups.google.de/groups?hl=de&lr=&threadm=3ACA7BB0.7020106%402cactus.com&rnum=7&a...

But, this posting is very old (2001-04-03), i'm using 7.4.6.


Is there now a way to get the total number of rows in a CURSOR?


Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    === 



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: how many tuples on a cursor?
  2005-05-02 07:13 how many tuples on a cursor? Andreas Kretschmer <akretschmer@despammed.com>
@ 2005-05-02 11:17 ` Christoph Haller <ch@rodos.fzk.de>
  2005-05-02 15:04   ` Re: how many tuples on a cursor? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Christoph Haller @ 2005-05-02 11:17 UTC (permalink / raw)
  To: Andreas Kretschmer <akretschmer@despammed.com>; +Cc: pgsql-sql

Andreas Kretschmer wrote:
> 
> Hello,
> 
> I want to know how many tuples there on a cursor, and i found
> http://groups.google.de/groups?hl=de&lr=&threadm=3ACA7BB0.7020106%402cactus.com&rnum=7&a...
> 
> But, this posting is very old (2001-04-03), i'm using 7.4.6.
> 
> Is there now a way to get the total number of rows in a CURSOR?
> 
> Andreas
> --

Assuming you are using the libpq interface, 
after FETCH ALL you'll get the number of rows 
by PQntuples(). 
What else seems to work is MOVE 2147483647 
(INT_MAX) and then get the max number of rows 
by PQcmdTuples(). 
Back to the beginning by FETCH ABSOLUTE 0. 
But I have no idea how expensive this MOVE is. 

Regards, Christoph



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: how many tuples on a cursor?
  2005-05-02 07:13 how many tuples on a cursor? Andreas Kretschmer <akretschmer@despammed.com>
  2005-05-02 11:17 ` Re: how many tuples on a cursor? Christoph Haller <ch@rodos.fzk.de>
@ 2005-05-02 15:04   ` Tom Lane <tgl@sss.pgh.pa.us>
  2005-05-02 15:20     ` Re: how many tuples on a cursor? Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2005-05-02 15:04 UTC (permalink / raw)
  To: Christoph Haller <ch@rodos.fzk.de>; +Cc: Andreas Kretschmer <akretschmer@despammed.com>; pgsql-sql

Christoph Haller <ch@rodos.fzk.de> writes:
> What else seems to work is MOVE 2147483647 
> (INT_MAX) and then get the max number of rows 
> by PQcmdTuples(). 

I'd suggest "MOVE FORWARD ALL" rather than hard-wiring assumptions
about the maximum possible value of infinity ;-)

> But I have no idea how expensive this MOVE is. 

The rows are all calculated internally --- about all you save compared
to a FETCH is data formatting and transmission.  If you really have to
know this number in advance of fetching the data, that's pretty much
what you have to do, but it will cost you ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: how many tuples on a cursor?
  2005-05-02 07:13 how many tuples on a cursor? Andreas Kretschmer <akretschmer@despammed.com>
  2005-05-02 11:17 ` Re: how many tuples on a cursor? Christoph Haller <ch@rodos.fzk.de>
  2005-05-02 15:04   ` Re: how many tuples on a cursor? Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-05-02 15:20     ` Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 0 replies; 4+ messages in thread

From: Christoph Haller @ 2005-05-02 15:20 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andreas Kretschmer <akretschmer@despammed.com>; pgsql-sql

Tom Lane wrote:
> 
> Christoph Haller <ch@rodos.fzk.de> writes:
> > What else seems to work is MOVE 2147483647
> > (INT_MAX) and then get the max number of rows
> > by PQcmdTuples().
> 
> I'd suggest "MOVE FORWARD ALL" rather than hard-wiring assumptions
> about the maximum possible value of infinity ;-)
> 

Of course. I should have read the manual on this more carefully. 

Regards, Christoph



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-05-02 15:20 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-05-02 07:13 how many tuples on a cursor? Andreas Kretschmer <akretschmer@despammed.com>
2005-05-02 11:17 ` Christoph Haller <ch@rodos.fzk.de>
2005-05-02 15:04   ` Tom Lane <tgl@sss.pgh.pa.us>
2005-05-02 15:20     ` Christoph Haller <ch@rodos.fzk.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox