how do i get num of recs inserted/deleted/updated in plpgsql

Started by Gauthier, Daveover 18 years ago3 messagesgeneral
Jump to latest
#1Gauthier, Dave
dave.gauthier@intel.com

Looking to capture the total number of records affected with
insert/delete/update from within a plpgsql (v7.4 on linux). Would be
nice to have this in an integer.

Thanks

-dave

#2Gauthier, Dave
dave.gauthier@intel.com
In reply to: Gauthier, Dave (#1)
Re: how do i get num of recs inserted/deleted/updated in plpgsql

Perhaps....

rowcnt integer;

...

get diagnostics rowcnt := row_count;

???

________________________________

From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Gauthier, Dave
Sent: Wednesday, August 01, 2007 12:05 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] how do i get num of recs inserted/deleted/updated in
plpgsql

Looking to capture the total number of records affected with
insert/delete/update from within a plpgsql (v7.4 on linux). Would be
nice to have this in an integer.

Thanks

-dave

#3Leif B. Kristensen
leif@solumslekt.org
In reply to: Gauthier, Dave (#1)
Re: how do i get num of recs inserted/deleted/updated in plpgsql

On Wednesday 1. August 2007 18:05, Gauthier, Dave wrote:

Looking to capture the total number of records affected with
insert/delete/update from within a plpgsql (v7.4 on linux). Would be
nice to have this in an integer.

http://www.varlena.com/GeneralBits/23.php

8<-----
How many rows were affected?
[GENERAL] pl-pgsql question 24-Apr-2003

In pl/pgsql, you can find out how many rows were affected by a statement
by using GET DIAGNOSTICS immediately after the statement in question.

This is how the statement is used with ROW_COUNT. With ROW_COUNT, the
statement before the GET DIAGNOSTICS must be an INSERT, UPDATE or
DELETE.

DECLARE
rowcount integer;
...
BEGIN
[INSERT | UPDATE | DELETE] ....
GET DIAGNOSTICS rowcount = ROW_COUNT;

The GET DIAGNOSTICS statement can also be used with LAST_OID to fetch
the OID of the last INSERT statement, if it had an OID. If the table
did not have OIDS, it returns 0.

Contributors: Vilson farias vilson.farias at digitro.com.br, Darren
Ferguson darren at crystalballinc.com, Dennis Gearon gearond at cvc.net
8<-----
--
Leif Biberg Kristensen | Registered Linux User #338009
http://solumslekt.org/ | Cruising with Gentoo/KDE
My Jazz Jukebox: http://www.last.fm/user/leifbk/