Re: 7.1 ESQL/C: how to get number of rows from a select?
Posted in 1996
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
In article <DvptJ5.Bp8@connex.sgh-net.de>, ag@connex.sgh-net.de says... > >A newbies question: > >I would like to know in advance how many rows will be returned from a >SELECT >statement, to be able to allocate my correspondig C-structures at once >. > >My first idea was to do a SELECT COUNT(...), but probably there is a m >ore >efficient way to get this information. (I have to admit that I dont kn >ow >how expensive this additional select would be...) > >Thanks in advance, >Andreas >-- >Andreas Godzina connex software GmbH Richthofenstr. 29 D-31137 H >ildesheim From informix FAQ: 6.12 Can I count the number of rows SELECTed, without using SELECT COUNT? No. Nor with SELECT COUNT(*) either, because by the time you get to execute the SELECT *, someone may have changed the tables. Stefan Gutsche, sg@ivu-berlin.de adds: Another option, faster than SELECT COUNT(*) is to: 1. UPDATE STATISTICS FOR TABLE [Table] 2. SELECT nrows FROM systables WHERE tabname = [Table] It is really faster than SELECT COUNT(*) and for a secure working you should lock the in exclusive mode. From personal experience (with SE), select count(*) is expensive. It is also faster to fetch a cursor and increment a counter in a for loop.