pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: Martin Marques <martin@bugs.unl.edu.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: Best way to know if there is a row
Date: Tue, 28 Sep 2004 15:24:13 +0300 (EEST)
Message-ID: <Pine.LNX.4.44.0409281518320.30263-100000@matrix.gatewaynet.com> (raw)
In-Reply-To: <200409280955.23773.martin@bugs.unl.edu.ar>

O Martin Marques Ýãñáøå óôéò Sep 28, 2004 :

> I have a bunch of queries in a system I'm finishing, and I bumped with a 
> question on performace.
> Which is the best way to solve this:
> 
> I need to know if there is at least one row in the relation that comes from a 
> determinated query. Which is the best way to do this:
> 
> (a) Build the query with "SELECT * ..." and after executing the query see if 
> numRows()>0
> (b) Build the query with "SELECT count(*) ...", fetch the row and see if 
> count>0

You could also try
(c) SELECT exists (select 1 ... limit 1) and test the boolean value
in the one and only row returned, where "..." is your clause
as in (a),(b).

> 
> I'm working with (a) because I see it better in performace, but I wanted to be 
> sure the numRows() will actually give me the exact amount of rows (had some 
> problems in the past with Informix).
> 
> The aplication is written in PHP.
> 
> 

-- 
-Achilleus




view thread (3+ messages)  latest in thread

Message-ID: <Pine.LNX.4.44.0409281518320.30263-100000@matrix.gatewaynet.com>
Permalink:  ../Pine.LNX.4.44.0409281518320.30263-100000@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.44.0409281518320.30263-100000@matrix.gatewaynet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: achill@matrix.gatewaynet.com, martin@bugs.unl.edu.ar
  Subject: Re: Best way to know if there is a row
  In-Reply-To: <Pine.LNX.4.44.0409281518320.30263-100000@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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