Plpgsql Language Feature?

Поиск
Список
Период
Сортировка
От David Hartwig
Тема Plpgsql Language Feature?
Дата
Msg-id 36C359C7.60932427@insightdist.com
обсуждение исходный текст
Ответы Re: [SQL] Plpgsql Language Feature?
Список pgsql-sql
In the context of a plpgsql script is a possible to access the number of rows effected by an UPDATE or DELETE statement?   It could be used  to simplify, and probably improve performance on, many scripts.   I would like to do something like:

    update foo set bar = bar + new.amount where key = new.key;

    if ROWS_UPDATED > 0 then
        --  This would be less likely to occur
        insert into foo (key, bar) values (new.key, new.bar);
    end if;

Otherwise I must construct  an additional SELECTstatement to see if the row exists.  Something like:

    select  1 from foo where key = new.key;
 
    if found then
        update foo set bar = bar + new.amount where key = new.key;
    else
        insert into foo (key, bar) values (new.key, new.bar);
    end if;

Might this be a worth while feature if it does not now exist?

TIA.

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

Предыдущее
От: TSchoessow@t-online.de (Thomas Schoessow)
Дата:
Сообщение: unsubscribe
Следующее
От: "Lawrenzo D'Wolcoto"
Дата:
Сообщение: PSQL SELECT Question.