Skip site navigation (1) Skip section navigation (2)

Getting a count from an update

From: Brian Hurt <bhurt(at)janestcapital(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Getting a count from an update
Date: 2006-12-14 19:56:51
Message-ID: 4581AC83.2020509@janestcapital.com (view raw or flat)
Thread:
Lists: pgsql-novice
Newbie question here: I want to be able to capture the count of the 
number of rows updated from an update command within SQL.  I know that 
psql prints out the result, I want to grab it within a function.  The 
update is a simple "UPDATE tablename SET col = value WHERE othercol = 
otherval;", which will generally update many dozens or hundreds of 
rows.  Currently I'm doing a select before doing the update, but since 
I'm doing a select count(*) I can't add a 'for update' to the end and 
lock the rows.  Is there a better way to do this?

Brian


Responses

pgsql-novice by date

Next:From: Richard Broersma JrDate: 2006-12-14 20:20:59
Subject: Re: Getting a count from an update
Previous:From: Aarni RuuhimäkiDate: 2006-12-14 07:05:47
Subject: Re: Upgrade to PGSQL 8.2 Problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group