Re: I guess I'm missing something here WRT FOUND

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ralph Smith <rsmith(at)10kinfo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: I guess I'm missing something here WRT FOUND
Date: 2010-11-09 19:21:42
Message-ID: 25787.1289330502@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ralph Smith <rsmith(at)10kinfo(dot)com> writes:
> <tt>Yeah your right Alban, that looks bad, but it was an artifact of
> 'try-this, try-this, no, try-this'.<br>
> <br>
> The table is empty, and unfortunately remains that way; nothing gets
> inserted.<br>
> I tried other variations, however FOUND just isn't behaving as I would
> think.<br>

(Please avoid html-encoded email.)

The original mail looked like you were trying to do

perform count(*) from something where something;
if found then ...

This will in fact *always* set FOUND, because the query always yields
exactly one row: that's the nature of aggregate functions. FOUND
doesn't respond to whether the result of count(*) was zero or nonzero,
but just to the fact that it did deliver a result row.

You probably wanted something like

perform 1 from something where something;
if found then ...

which will set FOUND depending on whether there are any rows matching
the where-clause. Or you could avoid FOUND altogether:

if exists(select 1 from something where something) then ...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Graham Leggett 2010-11-09 20:04:58 Re: Why facebook used mysql ?
Previous Message Ralph Smith 2010-11-09 19:11:12 [Fwd: Re: I guess I'm missing something here WRT FOUND]