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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: I guess I'm missing something here WRT FOUND
Дата
Msg-id 25787.1289330502@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: I guess I'm missing something here WRT FOUND  (Ralph Smith <rsmith@10kinfo.com>)
Список 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 по дате отправления:

Предыдущее
От: Ralph Smith
Дата:
Сообщение: [Fwd: Re: I guess I'm missing something here WRT FOUND]
Следующее
От: Graham Leggett
Дата:
Сообщение: Re: Why facebook used mysql ?