Re: Stored Procedure to Delete Rows and Return Count

Поиск
Список
Период
Сортировка
От Jonathan S. Katz
Тема Re: Stored Procedure to Delete Rows and Return Count
Дата
Msg-id 18DFE2AC-5753-454C-B84C-1A99D5095B0C@excoventures.com
обсуждение исходный текст
Ответ на Re: Stored Procedure to Delete Rows and Return Count  ("Jonathan S. Katz" <jonathan.katz@excoventures.com>)
Ответы RE: Stored Procedure to Delete Rows and Return Count  ("Dave Bolt" <dave@davebolt.co.uk>)
Список pgsql-sql

On Aug 29, 2018, at 5:50 PM, Jonathan S. Katz <jonathan.katz@excoventures.com> wrote:


On Aug 29, 2018, at 5:46 PM, Dave Bolt <dave@davebolt.co.uk> wrote:

Can someone give me a clue how this can be done and confirm that their solution has been tested so I know it's my end that has the problem, or better yet tell me what I'm doing wrong.

Being able to use a DELETE in a CTE was introduced in PostgreSQL 9.1.

Borrowing from an old post[1] I made this little function:

    CREATE FUNCTION delete_stuff (y int)
    RETURNS int
    AS $$
        DECLARE
            deleted int;
        BEGIN
            DELETE FROM a WHERE x = y;
            GET DIAGNOSTICS deleted = ROW_COUNT;
            RETURN deleted;
        END
    $$ LANGUAGE plpgsql;

which returns the total # of rows deleted by the above query, which seems like
it could be adapted for your purposes.

Hope this helps,

Jonathan


Вложения

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

Предыдущее
От: "Jonathan S. Katz"
Дата:
Сообщение: Re: Stored Procedure to Delete Rows and Return Count
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Stored Procedure to Delete Rows and Return Count