count() for a select statement?

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: count() for a select statement?
Date: 2002-10-01 17:46:22
Message-ID: 3D99DF6E.6090009@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there an efficient way to get a count of the number of rows returned
by this kind of query?

select id from products where name ILIKE 'TNT' UNION select id from
products where name ILIKE 'ATOM' UNION select id from products where
name ILIKE 'BOB'

I don't need any of the data returned, just a row count. The way I do it
now is to execute the query and use (in PHP) pg_numrows() on the result
set. But that mean the whole result set is being sent back to me when
all I need is a count ...

I've tried select count( select id from ...) but that didn't work ;)

Jc

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Johnson, Shaunn 2002-10-01 17:48:38 execute transaction / insert rows
Previous Message Roland Roberts 2002-10-01 17:43:02 Re: [GENERAL] arrays