Postgresql-Get the number of rows affected

You will find a way below to get the number of rows affected by an UPDATE or a DELETE statement.

 
CREATE FUNCTION update_foobar(id INT, field1 VARCHAR(40))
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
    -- some variables declarations
BEGIN
    -- UPDATE or DELETE
    -- then 
    GET DIAGNOSTICS ru := ROW_COUNT;
    RETURN ru;
END;
$$ ;

About Saïd

Software developer.
This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.