Get the number of records of a result set

Started by Eugenio Tacchiniabout 18 years ago4 messagesgeneral
Jump to latest
#1Eugenio Tacchini
eugenio.tacchini@elfo.net

Hello,
I'm writing a function in PL/pgSQL and I would like to know if there
is a method to get the number of records in a result set, after a
select query, without executing the same query using COUNT(*).

Thanks.

Regards,

Eugenio.

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Eugenio Tacchini (#1)
Re: Get the number of records of a result set

Hello

http://www.postgresql.org/docs/8.2/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS

regards
Pavel Stehule

Show quoted text

On 30/01/2008, Eugenio Tacchini <eugenio.tacchini@elfo.net> wrote:

Hello,
I'm writing a function in PL/pgSQL and I would like to know if there
is a method to get the number of records in a result set, after a
select query, without executing the same query using COUNT(*).

Thanks.

Regards,

Eugenio.

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

#3Ow Mun Heng
Ow.Mun.Heng@wdc.com
In reply to: Eugenio Tacchini (#1)
Re: Get the number of records of a result set

On Wed, 2008-01-30 at 09:14 +0100, Eugenio Tacchini wrote:

Hello,
I'm writing a function in PL/pgSQL and I would like to know if there
is a method to get the number of records in a result set, after a
select query, without executing the same query using COUNT(*).

not sure what exactly you mean, but perhaps this could help?

del_stime := timeofday();
execute del_qry;
del_etime := timeofday();

GET DIAGNOSTICS del_rows = ROW_COUNT;

This would get you the # of rows inserted into the destination table
etc.

#4Eugenio Tacchini
eugenio.tacchini@elfo.net
In reply to: Ow Mun Heng (#3)
Re: Get the number of records of a result set

At 16.35 30/01/2008 +0800, Ow Mun Heng wrote:

not sure what exactly you mean, but perhaps this could help?

del_stime := timeofday();
execute del_qry;
del_etime := timeofday();

GET DIAGNOSTICS del_rows = ROW_COUNT;

This would get you the # of rows inserted into the destination table
etc.

This is exactly what I mean, thanks a lot to you and Pavel.

Eugenio.