Re: PL/PGSQL help for getting number of rows matched.

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: PL/PGSQL help for getting number of rows matched.
Дата
Msg-id Pine.LNX.4.44.0311101304140.15903-100000@kix.fsv.cvut.cz
обсуждение исходный текст
Ответ на PL/PGSQL help for getting number of rows matched.  (Rajesh Kumar Mallah <mallah@trade-india.com>)
Ответы Re: PL/PGSQL help for getting number of rows matched.
Re: PL/PGSQL help for getting number of rows matched.
Список pgsql-general
Hello,

it isn't problem. You can write

SELECT INTO ....
IF FOUND THEN
 ...
END IF

or

SELECT INTO  ..
GET DIAGNOSTICS variable = ROW_COUNT;
IF variable > 0 THEN
  ...
END IF

You can see on
http://developer.postgresql.org/docs/postgres/plpgsql-statements.html#PLPGSQL-SELECT-INTO

Regards
Pavel


On Mon, 10 Nov 2003, Rajesh Kumar Mallah wrote:

>
> Hi,
>
> We need to implement following logic efficiently.
>
> SELECT * from some_table where .... [ Query 1 ]
>
> IF rows_matched = 1 THEN
>
>     use the single row that matched.
>
> ELSIF
>
>     loop thru the results of [Query 1]
>
> END IF;
>
>
> Currently i am doing select count(*) for getting rows_matched
> in the top and repeating the same query in both branches of IF
> to get the data of matching rows.
>
> I have tried GET DIAGNOSTICS ROW_COUNT but for
> "SELECTS" if returns 0 or 1 based on matching
>
> I am sure there exists better methods. Kindly post a link
> to better documentation of pl/pgsql or point out section in
> the standard docs that discuss this issue.
>
> Regds
> Mallah.
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>


В списке pgsql-general по дате отправления:

Предыдущее
От: Krzysztof Labiak
Дата:
Сообщение: PGSQL technical documentation
Следующее
От: "Nigel J. Andrews"
Дата:
Сообщение: Re: PL/PGSQL help for getting number of rows matched.