pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to retrieve how many rows are affected after doing an INSERT statement
3+ messages / 3 participants
[nested] [flat]

* How to retrieve how many rows are affected after doing an INSERT statement
@ 2005-04-12 15:41 jing han <jing_han_66@yahoo.com>
  2005-04-12 15:56 ` Re: How to retrieve how many rows are affected after doing an INSERT statement Michael Fuhr <mike@fuhr.org>
  2005-04-13 02:00 ` Re: How to retrieve how many rows are affected after doing an INSERT statement Greg Sabino Mullane <greg@turnstep.com>
  0 siblings, 2 replies; 3+ messages in thread

From: jing han @ 2005-04-12 15:41 UTC (permalink / raw)
  To: pgsql-interfaces

Hello,

When we use PostgreSQL with Perl, we can retrieve
Error messages from database handler, say, if my
database handler is presented as $dbh, then I use
$dbh->errstr() can get error message like:

ERROR: Cannot insert a duplicate key into unique index
a_dbtable_pkey.

Is there a way to retriever from $dbh how many rows
are affected after doing an insert statement, and how
to present this? 

I tried $dbh->rowcount(), it doesn't work, So what's
the exact expression?

Any help will be appreciated.


jing 


		
__________________________________ 
Yahoo! Mail Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to retrieve how many rows are affected after doing an INSERT statement
  2005-04-12 15:41 How to retrieve how many rows are affected after doing an INSERT statement jing han <jing_han_66@yahoo.com>
@ 2005-04-12 15:56 ` Michael Fuhr <mike@fuhr.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Fuhr @ 2005-04-12 15:56 UTC (permalink / raw)
  To: jing han <jing_han_66@yahoo.com>; +Cc: pgsql-interfaces

On Tue, Apr 12, 2005 at 08:41:24AM -0700, jing han wrote:
> 
> Is there a way to retriever from $dbh how many rows
> are affected after doing an insert statement, and how
> to present this? 

See the DBI documentation (e.g., "perldoc DBI") and search for
"rows" or "number of rows".

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to retrieve how many rows are affected after doing an INSERT statement
  2005-04-12 15:41 How to retrieve how many rows are affected after doing an INSERT statement jing han <jing_han_66@yahoo.com>
@ 2005-04-13 02:00 ` Greg Sabino Mullane <greg@turnstep.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Greg Sabino Mullane @ 2005-04-13 02:00 UTC (permalink / raw)
  To: pgsql-interfaces


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> Is there a way to retriever from $dbh how many rows
> are affected after doing an insert statement, and how
> to present this?

You can grab it directly from the execute, or use the rows() method:

$sth = $dbh->prepare("INSERT INTO mytable SELECT * FROM mytable");
$count = $sth->execute();
print "Count is $count\n";
$count = $sth->rows;
print "Count is still $count\n";

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200504122200
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8

-----BEGIN PGP SIGNATURE-----

iD8DBQFCXH1TvJuQZxSWSsgRAtmzAKDWF3HFWNDl0ITAB/vJkdSSBjW2nACfWqXA
vqi47yulZB40WF7w6WuibeQ=
=QI53
-----END PGP SIGNATURE-----





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-04-13 02:00 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-12 15:41 How to retrieve how many rows are affected after doing an INSERT statement jing han <jing_han_66@yahoo.com>
2005-04-12 15:56 ` Michael Fuhr <mike@fuhr.org>
2005-04-13 02:00 ` Greg Sabino Mullane <greg@turnstep.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox