Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?
 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/

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux