Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1308C9FB5CB for ; Wed, 28 Mar 2007 18:18:41 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 62435-04 for ; Wed, 28 Mar 2007 18:18:37 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.190]) by postgresql.org (Postfix) with ESMTP id 574319FB799 for ; Wed, 28 Mar 2007 18:18:37 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id x4so3805917nfb for ; Wed, 28 Mar 2007 14:18:35 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=lktrgK8grY1ib3rHKyDblTjlEEnb7uuH5ClAIfYT8TqN43PSs0P4DQqfndXWnwNW0pHK2UDVRGy1ygIY0XCAvNhxqkB4GmPC+cLiPHMWd1UJKlf32kYL2zxQpNt8AljQLZ3cjygwN8oyjMHQUJ+vePiaalM8c+z/kXU/GfLDvvs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=RcogAtUm5/6cyGhCKFuoikw7E1ebH8/JCwGlV4nSUdLfXiu9bPTFk+YFUmkfLCqdQFn28JIcSLCjoKN32Ip0wvLTUJXgjYEjham14oTwhqqASyvsA472c8qNBROn/CN3BIvH8QDKLpeFdjueARpXqpirZwiU4FaTb5VNyK4mWGQ= Received: by 10.82.163.13 with SMTP id l13mr19759206bue.1175116715114; Wed, 28 Mar 2007 14:18:35 -0700 (PDT) Received: by 10.82.114.5 with HTTP; Wed, 28 Mar 2007 14:18:34 -0700 (PDT) Message-ID: <5b599cc10703281418j65c65ce7g537c7cc7fb32cbc5@mail.gmail.com> Date: Wed, 28 Mar 2007 14:18:34 -0700 From: "Gavin M. Roy" To: "Mihail Mihailov" Subject: Re: Retrieving result of COUNT(*) with PHP Cc: pgsql-php@postgresql.org In-Reply-To: <20070329000511.qidyijwozuo0w0w4@imp3.uta.fi> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_42385_27467695.1175116714960" References: <20070329000511.qidyijwozuo0w0w4@imp3.uta.fi> X-Google-Sender-Auth: c71d7f726af2ea6c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/55 X-Sequence-Number: 3767 ------=_Part_42385_27467695.1175116714960 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 3/28/07, Mihail Mihailov wrote: > > > Another way to calculate number of rows in the result is to use > pg_num_rows function. > $res = pg_query("SELECT COUNT(*) AS result_count FROM etc. WHERE etc."); > $count = pg_num_rows($res); I dont think this will work as expected. PostgreSQL will return 1 row and your $count var will be 1. If you do SELECT * FROM it would return the proper result. Not very effective for speed though. http://www.varlena.com/GeneralBits/120.php has some good suggestions for dealing with count(*) speed issues. Gavin ------=_Part_42385_27467695.1175116714960 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
On 3/28/07, Mihail Mihailov <Mihail.Mihailov@uta.fi> wrote:

Another way to calculate number of rows in the result is to use
pg_num_rows function.
$res = pg_query("SELECT COUNT(*) AS result_count FROM etc. WHERE etc.");
$count = pg_num_rows($res);

I dont think this will work as expected.  PostgreSQL will return 1 row and your $count var will be 1.  If you do SELECT * FROM it would return the proper result.  Not very effective for speed though.

http://www.varlena.com/GeneralBits/120.php has some good suggestions for dealing with count(*) speed issues.

Gavin


------=_Part_42385_27467695.1175116714960--