Unix Technical Forum

How to find the number of rows deleted

This is a discussion on How to find the number of rows deleted within the Pgsql General forums, part of the PostgreSQL category; --> I ran DELETE command from my ODBC client application. I want to get the number of rows deleted by ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 04:59 AM
Andrus
 
Posts: n/a
Default How to find the number of rows deleted

I ran DELETE command from my ODBC client application.
I want to get the number of rows deleted by this DELETE command.

I read the DELETE command docs but havent found any function.

Any idea ?

Andrus.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 05:00 AM
Ropel
 
Posts: n/a
Default Re: How to find the number of rows deleted

At least, you can do a "select count(*) from ..." just before the
delete, better if inside a transaction, if the query itself is not too
much expensive

Andrus wrote:

>I ran DELETE command from my ODBC client application.
>I want to get the number of rows deleted by this DELETE command.
>
>I read the DELETE command docs but havent found any function.
>
>Any idea ?
>
>Andrus.
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>
>
>
>




---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 05:00 AM
Andrus
 
Posts: n/a
Default Re: How to find the number of rows deleted

Ropel, thank you.

I'm looking for a better solution because

1. Some deletes take big amount of time. This increases run time a LOT

2. This requires the use of transaction if somebody changes data between
SELECT COUNT(*) and DELETE commands.
When transaction isolation level I must set for this ? Can I use default
isolation level?

Andrus.

> At least, you can do a "select count(*) from ..." just before the delete,
> better if inside a transaction, if the query itself is not too much
> expensive
>
>>I ran DELETE command from my ODBC client application.
>>I want to get the number of rows deleted by this DELETE command.
>>
>>I read the DELETE command docs but havent found any function.
>>
>>Any idea ?
>>
>>Andrus.
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 3: Have you checked our extensive FAQ?
>>
>> http://www.postgresql.org/docs/faq
>>
>>
>>

>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 05:00 AM
Tom Lane
 
Posts: n/a
Default Re: How to find the number of rows deleted

"Andrus" <eetasoft@online.ee> writes:
> I ran DELETE command from my ODBC client application.
> I want to get the number of rows deleted by this DELETE command.


I'm sure ODBC provides a way to do that, but you're asking the wrong
list about what it is ... try pgsql-odbc.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 05:00 AM
John DeSoi
 
Posts: n/a
Default Re: How to find the number of rows deleted


On Jul 18, 2005, at 7:00 AM, Andrus wrote:

> I ran DELETE command from my ODBC client application.
> I want to get the number of rows deleted by this DELETE command.
>
> I read the DELETE command docs but havent found any function.
>
> Any idea ?


I don't use ODBC, but you should get that directly back from the
DELETE command. Is there not a way to get the command return value
with your ODBC driver?

From the DELETE docs:

Outputs

On successful completion, a DELETE command returns a command tag of
the form

DELETE count
The count is the number of rows deleted. If count is 0, no rows
matched the condition (this is not considered an error).





John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-09-2008, 05:00 AM
Greg Patnude
 
Posts: n/a
Default Re: How to find the number of rows deleted

After an application updates, deletes, or inserts rows, it can call
SQLRowCount to determine how many rows were affected. SQLRowCount returns
this value whether or not the rows were updated, deleted, or inserted by
executing an UPDATE, DELETE, or INSERT statement, by executing a positioned
update or delete statement, or by calling SQLSetPos.

If a batch of SQL statements is executed, the count of affected rows might
be a total count for all statements in the batch or individual counts for
each statement in the batch. For more information, see Batches of SQL
Statements and Multiple Results.

The number of affected rows is also returned in the SQL_DIAG_ROW_COUNT
diagnostic header field in the diagnostic area associated with the statement
handle. However, the data in this field is reset after every function call
on the same statement handle, whereas the value returned by SQLRowCount
remains the same until a call to SQLBulkOperations, SQLExecute,
SQLExecDirect, SQLPrepare, or SQLSetPos.

And Tom is right....



"Andrus" <eetasoft@online.ee> wrote in message
news:dbg24r$27d4$1@news.hub.org...
>I ran DELETE command from my ODBC client application.
> I want to get the number of rows deleted by this DELETE command.
>
> I read the DELETE command docs but havent found any function.
>
> Any idea ?
>
> Andrus.
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-09-2008, 05:00 AM
Andrus
 
Posts: n/a
Default Re: How to find the number of rows deleted

My ODBC client is Microsoft Visual FoxPro

I ran delete command using its sqlexec() function like:

SQLEXEC(nConnhandle, "DELETE FROM mytable")

sqlexec() function returns the result from ordinary select table in a
cursor SQLRESULT

Unfortunately, no result is returned if DELETE command is executed.
There is no SQLRowCount function in FoxPro.

If Microsoft SQL server returns the number of rows from last command in a
variable something like @@RowCount.

I'm expecting that Postgres has connection level function like currval()
which returns the result of rows affected by last command. So I can execute

SELECT rowcount();

in Postgres.

I can retrieve the connection handle value but I donät know hot to get the
row count from it.

Any idea ?

Andrus.

"Greg Patnude" <gpatnude@hotmail.com> wrote in message
news:dbgfg9$213i$1@news.hub.org...
> After an application updates, deletes, or inserts rows, it can call
> SQLRowCount to determine how many rows were affected. SQLRowCount returns
> this value whether or not the rows were updated, deleted, or inserted by
> executing an UPDATE, DELETE, or INSERT statement, by executing a
> positioned update or delete statement, or by calling SQLSetPos.
>
> If a batch of SQL statements is executed, the count of affected rows might
> be a total count for all statements in the batch or individual counts for
> each statement in the batch. For more information, see Batches of SQL
> Statements and Multiple Results.
>
> The number of affected rows is also returned in the SQL_DIAG_ROW_COUNT
> diagnostic header field in the diagnostic area associated with the
> statement handle. However, the data in this field is reset after every
> function call on the same statement handle, whereas the value returned by
> SQLRowCount remains the same until a call to SQLBulkOperations,
> SQLExecute, SQLExecDirect, SQLPrepare, or SQLSetPos.
>
> And Tom is right....
>
>
>
> "Andrus" <eetasoft@online.ee> wrote in message
> news:dbg24r$27d4$1@news.hub.org...
>>I ran DELETE command from my ODBC client application.
>> I want to get the number of rows deleted by this DELETE command.
>>
>> I read the DELETE command docs but havent found any function.
>>
>> Any idea ?
>>
>> Andrus.
>>

>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-09-2008, 05:00 AM
Andrus
 
Posts: n/a
Default Re: How to find the number of rows deleted

>> I ran DELETE command from my ODBC client application.
>> I want to get the number of rows deleted by this DELETE command.

>
> I'm sure ODBC provides a way to do that, but you're asking the wrong
> list about what it is ... try pgsql-odbc.


Tom,

pgsql.odbc newsgroup has only 5 messages in the whole this year. None of
them has got any replies.

I posted this question also pgsql.interfaces.odbc newgroup some days ago but
havent got
any reply.

pgsql.interfaces.odbc has lower traffic. 50% on messages get replies.

pgsql.general has much higher traffic. 80% of messages get replies.

Andrus.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-09-2008, 05:00 AM
Scott Marlowe
 
Posts: n/a
Default Re: How to find the number of rows deleted

On Mon, 2005-07-18 at 11:53, Andrus wrote:
> >> I ran DELETE command from my ODBC client application.
> >> I want to get the number of rows deleted by this DELETE command.

> >
> > I'm sure ODBC provides a way to do that, but you're asking the wrong
> > list about what it is ... try pgsql-odbc.

>
> Tom,
>
> pgsql.odbc newsgroup has only 5 messages in the whole this year. None of
> them has got any replies.
>
> I posted this question also pgsql.interfaces.odbc newgroup some days ago but
> havent got
> any reply.
>
> pgsql.interfaces.odbc has lower traffic. 50% on messages get replies.
>
> pgsql.general has much higher traffic. 80% of messages get replies.


I think you're making the classic mistake of equating the usenet news
versions of a list with the actual mailing list.

Take a look here:

http://archives.postgresql.org/pgsql...07/threads.php

That's the list for just July, and there's easily 40 or more messages
there.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-09-2008, 05:01 AM
Paul Thomas
 
Posts: n/a
Default Re: How to find the number of rows deleted


On 18/07/2005 17:47 Andrus wrote:
> Unfortunately, no result is returned if DELETE command is executed.
> There is no SQLRowCount function in FoxPro.


That's probably a feature of the language and will be so regardless of the
database used. I expect it wraps the ODBC APIs up in a more managable form.

Paul Thomas
+------------------------------+-------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for Business |
| Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+-------------------------------------------+

---------------------------(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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com