Re: I guess I'm missing something here WRT FOUND - Mailing list pgsql-general

From Tom Lane
Subject Re: I guess I'm missing something here WRT FOUND
Date
Msg-id 25787.1289330502@sss.pgh.pa.us
Whole thread Raw
In response to Re: I guess I'm missing something here WRT FOUND  (Ralph Smith <rsmith@10kinfo.com>)
List pgsql-general
Ralph Smith <rsmith@10kinfo.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

pgsql-general by date:

Previous
From: Ralph Smith
Date:
Subject: [Fwd: Re: I guess I'm missing something here WRT FOUND]
Next
From: Graham Leggett
Date:
Subject: Re: Why facebook used mysql ?