473,670 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to capture rows affected via merge command?

I've got a batch etl process in which I typically wrap DML with selects
in order to capture the number of rows affected. For example:
SELECT 'rows updated', COUNT(*)
FROM NEW TABLE
( UPDATE stage_asset
SET ip_int = ip_to_bigint(ip _string)
WHERE ip_int IS NULL )

How can I do this for a merge? For example:

MERGE INTO asset_component comp
USING stage_asset stag
ON comp.asset_id = stag.core_asset _id
AND comp.asset_comp onent_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_na me ,

comp.os_id = stag.core_os_id
,
comp.asset_comp onent_name = stag.core_os_na me
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component _type,
asset_component _name,
os_name,
os_id )
VALUES (stag.core_asse t_id,
'os',
stag.core_os_na me,
stag.core_os_id )

Thanks in advance!

Ken

Sep 4 '06 #1
4 7058
kenfar wrote:
I've got a batch etl process in which I typically wrap DML with selects
in order to capture the number of rows affected. For example:
SELECT 'rows updated', COUNT(*)
FROM NEW TABLE
( UPDATE stage_asset
SET ip_int = ip_to_bigint(ip _string)
WHERE ip_int IS NULL )

How can I do this for a merge? For example:

MERGE INTO asset_component comp
USING stage_asset stag
ON comp.asset_id = stag.core_asset _id
AND comp.asset_comp onent_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_na me ,

comp.os_id = stag.core_os_id
,
comp.asset_comp onent_name = stag.core_os_na me
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component _type,
asset_component _name,
os_name,
os_id )
VALUES (stag.core_asse t_id,
'os',
stag.core_os_na me,
stag.core_os_id )
Unfortunately no can do.
FWIW, SELECT FROM MERGE is on my personal wish-list too.

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #2
Serge Rielau wrote:
kenfar wrote:
>I've got a batch etl process in which I typically wrap DML with selects
in order to capture the number of rows affected. For example:
SELECT 'rows updated', COUNT(*)
FROM NEW TABLE
( UPDATE stage_asset
SET ip_int = ip_to_bigint(ip _string)
WHERE ip_int IS NULL )

How can I do this for a merge? For example:

MERGE INTO asset_component comp
USING stage_asset stag
ON comp.asset_id = stag.core_asset _id
AND comp.asset_comp onent_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_na me ,

comp.os_id = stag.core_os_id
,
comp.asset_comp onent_name = stag.core_os_na me
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component _type,
asset_component _name,
os_name,
os_id )
VALUES (stag.core_asse t_id,
'os',
stag.core_os_na me,
stag.core_os_id )
Unfortunately no can do.
FWIW, SELECT FROM MERGE is on my personal wish-list too.
BTW, you are aware that you can retrieve the rows affected from the
SQLCA.ERRD[3] or in SQL PL: GET DIAGNOSTICS rcnt = ROW_COUNT

And that, of course, works also with MERGE
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #3
Serge Rielau wrote:
BTW, you are aware that you can retrieve the rows affected from the
SQLCA.ERRD[3] or in SQL PL: GET DIAGNOSTICS rcnt = ROW_COUNT

And that, of course, works also with MERGE
Thanks Serge. I'm piloting this process within a bash shell, and so
calling it like this:
sql="SELECT 'rows updated: ', COUNT(*) \
FROM NEW TABLE \
( UPDATE core.stage_asse t \
SET core_org_id = $org_id \
WHERE LOWER(account) = '$account' ) "
db2 -x "$sql"
rc=$?
if [ "$rc" != "0" ]; then
abort $rc
fi

Is there a way to get to the SQLCA from bash (or any shell
interpreter)?

Thanks again,

Ken

Sep 4 '06 #4
kenfar wrote:
Serge Rielau wrote:
>BTW, you are aware that you can retrieve the rows affected from the
SQLCA.ERRD[3] or in SQL PL: GET DIAGNOSTICS rcnt = ROW_COUNT

And that, of course, works also with MERGE

Thanks Serge. I'm piloting this process within a bash shell, and so
calling it like this:
sql="SELECT 'rows updated: ', COUNT(*) \
FROM NEW TABLE \
( UPDATE core.stage_asse t \
SET core_org_id = $org_id \
WHERE LOWER(account) = '$account' ) "
db2 -x "$sql"
rc=$?
if [ "$rc" != "0" ]; then
abort $rc
fi

Is there a way to get to the SQLCA from bash (or any shell
interpreter)?
Try the -a option.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5081
by: Chris Stromberger | last post by:
When issuing updates in mysql (in the console window), mysql will tell you if any rows matched and how many rows were updated (see below). I know how to get number of rows udpated using MySQLdb, but is there any way to get the number of rows matched? I want to find out, when rows updated = 0, if there were no updates because the row wasn't found (rows matched will = 0) or because the update would not have changed any data (rows matched =...
3
2779
by: Tome73 | last post by:
How can I easily add the rows of DataTable1 to the rows of DataTable2. Both queries are from the same table. I can always use the column names with myRow, but I was wishing for a shortcut. When I try this it doesn’t work. for (int i = 0; i < dataTable1.Rows.Count; i++) { myRow = dataTable2.NewRow(); myRow = dataTable1.Rows; dataTable2.Rows.Add(myRow);
7
12067
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound to know this number after the first FETCH, isn't it? On a side note, why queries using LIMIT are SO terribly slow, compared to cursors and sometimes even ones without LIMIT? Shouldn't LIMIT be internally implemented using cursor mechanism then?...
0
1494
by: Mark Barinstein | last post by:
Hello. W2K, db2 v7, FP10a. Before now our replication worked properly. But some days ago capture suddenly stopped loggin and filling cd tables without any messages. The last message was like this: -- 2004-03-03-09:17:36 ASN0105I: Data that has been copied was pruned from the change data table ASN.IBMSNAP_UOW at SEQ = 00000000006EFDC2DB55 for 2
12
1993
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they are initally added to the recordset. I create a dataset, which begins empty after the initial .Fill. Then I create several rows with some default information, leaving one
2
2103
by: muntyanu | last post by:
Hi all, I have problem when merging existing DataTable into new dataset. DataSet ds = new DataSet(); while ( done ) { // fill myCustomDataSet.MyTable with data ds.Merge( myCustomDataSet.MyTable, bPreserveChanges, MissingSchemaAction.Add ); ds.AcceptChanges(); // tried with and without this line
11
2546
by: UDBDBA | last post by:
Hi: This is a merge questions which has been posted and answered... in my case need more clairification when target table (tableB) matched multiple rows to be updated based on the ON condition for a single row from source table (tableA). There is a one to many relationship from source to target table (because of the ON condition). We also know upfront that thsi merge will result in all update and no inserts. The source table is tableA...
2
4568
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
3
15967
by: Carl K | last post by:
using MySQLdb, I do cursor.execute("update...") How can I tell how many rows were affected ? Carl K
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.