473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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_component_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_name ,

comp.os_id = stag.core_os_id
,
comp.asset_component_name = stag.core_os_name
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component_type,
asset_component_name,
os_name,
os_id )
VALUES (stag.core_asset_id,
'os',
stag.core_os_name,
stag.core_os_id )

Thanks in advance!

Ken

Sep 4 '06 #1
4 7024
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_component_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_name ,

comp.os_id = stag.core_os_id
,
comp.asset_component_name = stag.core_os_name
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component_type,
asset_component_name,
os_name,
os_id )
VALUES (stag.core_asset_id,
'os',
stag.core_os_name,
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_component_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_name ,

comp.os_id = stag.core_os_id
,
comp.asset_component_name = stag.core_os_name
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component_type,
asset_component_name,
os_name,
os_id )
VALUES (stag.core_asset_id,
'os',
stag.core_os_name,
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_asset \
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_asset \
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
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,...
3
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...
7
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...
0
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...
12
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...
2
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(...
11
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...
2
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.