473,507 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hekp updating/moving

I loaded a flat file into an SQL table and verified the data. Now I want
to move the data from the input table to the real table. I thought to
use a SQL statement like:

update is2.animals t1 join nullid.nalfherd_in t2
on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
set t1.color=t2.color
;

where t1 is the real table and t2 it the input table. I know I can
achieve this in an SQL procedure, but I was looking for an easier (and
probably more efficient) way.

I also think updating a view which joins the tables will work, but that
gets keyboard intensive, especially for me, with only one hand.

The real problem has 8 tables to be updated from 3 input tables with
about 500 columns between them.

Nov 12 '05 #1
4 2606
update is2.animals t1 join nullid.nalfherd_in t2
on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
set t1.color=t2.color
; Interesting syntax, not supported by any DBMS I know of ;-)

MERGE INTO is2.animals t1
USING nullid.nalfherd_in t2
ON on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
WHEN MATCHED THEN UPDATE SET t1.color=t2.color;

Preferably you shoudl be on V8.1 FP5 since there have been numerous
performance improvements for MERGE.

For older releases:
UPDATE is2.animals t1
SET t1.color = (SELECT t2.color FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno)
WHERE EXISTS(SELECT 1 FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno);
The real problem has 8 tables to be updated from 3 input tables with
about 500 columns between them.

Interesting flow. This is a fact table with 7 dimension tables?
If you coudl post a more elaborate example that woudl be helpful.
In general DB2 does not support update through JOIN only through UNION ALL.
You may be able to use SELECT FROM UPDATE and pipeline the updates in a
common table expression:
WITH u1 AS (SELECT ... FROM NEW TABLE(UPDATE T1 INCLUDE (...) SET ....)
u2 AS (SELECT ... FROM NEW TABLE (UPDATE T2 INCLUDE (...) SET ...
= (FROM y1 ...)...
....

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
update is2.animals t1 join nullid.nalfherd_in t2
on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
set t1.color=t2.color
; Interesting syntax, not supported by any DBMS I know of ;-)

MERGE INTO is2.animals t1
USING nullid.nalfherd_in t2
ON on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
WHEN MATCHED THEN UPDATE SET t1.color=t2.color;

Preferably you shoudl be on V8.1 FP5 since there have been numerous
performance improvements for MERGE.

For older releases:
UPDATE is2.animals t1
SET t1.color = (SELECT t2.color FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno)
WHERE EXISTS(SELECT 1 FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno);
The real problem has 8 tables to be updated from 3 input tables with
about 500 columns between them.

Interesting flow. This is a fact table with 7 dimension tables?
If you coudl post a more elaborate example that woudl be helpful.
In general DB2 does not support update through JOIN only through UNION ALL.
You may be able to use SELECT FROM UPDATE and pipeline the updates in a
common table expression:
WITH u1 AS (SELECT ... FROM NEW TABLE(UPDATE T1 INCLUDE (...) SET ....)
u2 AS (SELECT ... FROM NEW TABLE (UPDATE T2 INCLUDE (...) SET ...
= (FROM y1 ...)...
....

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
Serge Rielau wrote:
update is2.animals t1 join nullid.nalfherd_in t2
on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
set t1.color=t2.color
;


Interesting syntax, not supported by any DBMS I know of ;-)

MERGE INTO is2.animals t1
USING nullid.nalfherd_in t2
ON on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
WHEN MATCHED THEN UPDATE SET t1.color=t2.color;

Preferably you shoudl be on V8.1 FP5 since there have been numerous
performance improvements for MERGE.

For older releases:
UPDATE is2.animals t1
SET t1.color = (SELECT t2.color FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno)
WHERE EXISTS(SELECT 1 FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno);
The real problem has 8 tables to be updated from 3 input tables with
about 500 columns between them.


Interesting flow. This is a fact table with 7 dimension tables?
If you coudl post a more elaborate example that woudl be helpful.
In general DB2 does not support update through JOIN only through UNION ALL.
You may be able to use SELECT FROM UPDATE and pipeline the updates in a
common table expression:
WITH u1 AS (SELECT ... FROM NEW TABLE(UPDATE T1 INCLUDE (...) SET ....)
u2 AS (SELECT ... FROM NEW TABLE (UPDATE T2 INCLUDE (...) SET ...
= (FROM y1 ...)...
...


I knew it was invalid, it was, in some sense, illustrative of what I
wanted to do. I also really do know how to spell heLp, evidence to the
contrary.

Thanks for the pointers. The second looks slower than molasses uphill in
February unless the optimizer is almost telepathic in figuring out what
I mean from what I say. I am running 8.1.5 so the MERGE solution should
work for me.

Where did you find the documentation for the MERGE command? I have d/l'd
the _SQL Reference Volume 2_ from the IBM site and it doesn't show MERGE
as a statement (it goes from 'LOCK TABLE' straight to 'OPEN').

The real problem is I am getting the updates/addition to my real, almost
correctly designed (IMNSHO :-), database from several sources which use
different views of the same data. The data pertains to animals, and I
have separate tables for things like birth data, weaning data, genetic
fitness data, etc., since we almost never know all of the data for one
animal, or it doesn't pertain to a particular animal. The saving in
space/retrieval time is significant because the ultimate goal is to have
10^8 animals in the database. Unfortunately, my data suppliers see the
data differently, so there could be anywhere from 1 (massive) table
which would update each of my tables to a table set which is isomorphic
to my table set modulo column order. Since my data suppliers cannot
decide on a common unique identifier, I am using a generated field for
the identification of each animal and mapping the different suppliers
(not necessarily UNIQUE, especially over time) identifier to it. I do
this in an SQL procedure which seems to run forever. all of the
"dependent" tables use this same key. To make the problem even more
interesting each supplier presents pedigree data differently, some times
causing as many as 15 animals to be added to the main table for each
input record!

Which leads to another question: can I use the MERGE statement to update
a column which IS NOT NULL, or does it operate similarly to the COALESCE
function? From the use of SET in the statement, it would appear that
updates are possible. Also like UPDATE's SET operand, there can be
multiple attributes set in one statement, right?

Nov 12 '05 #4
Serge Rielau wrote:
update is2.animals t1 join nullid.nalfherd_in t2
on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
set t1.color=t2.color
;


Interesting syntax, not supported by any DBMS I know of ;-)

MERGE INTO is2.animals t1
USING nullid.nalfherd_in t2
ON on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
WHEN MATCHED THEN UPDATE SET t1.color=t2.color;

Preferably you shoudl be on V8.1 FP5 since there have been numerous
performance improvements for MERGE.

For older releases:
UPDATE is2.animals t1
SET t1.color = (SELECT t2.color FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno)
WHERE EXISTS(SELECT 1 FROM nullid.nalfherd_in t2
WHERE t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno);
The real problem has 8 tables to be updated from 3 input tables with
about 500 columns between them.


Interesting flow. This is a fact table with 7 dimension tables?
If you coudl post a more elaborate example that woudl be helpful.
In general DB2 does not support update through JOIN only through UNION ALL.
You may be able to use SELECT FROM UPDATE and pipeline the updates in a
common table expression:
WITH u1 AS (SELECT ... FROM NEW TABLE(UPDATE T1 INCLUDE (...) SET ....)
u2 AS (SELECT ... FROM NEW TABLE (UPDATE T2 INCLUDE (...) SET ...
= (FROM y1 ...)...
...


I knew it was invalid, it was, in some sense, illustrative of what I
wanted to do. I also really do know how to spell heLp, evidence to the
contrary.

Thanks for the pointers. The second looks slower than molasses uphill in
February unless the optimizer is almost telepathic in figuring out what
I mean from what I say. I am running 8.1.5 so the MERGE solution should
work for me.

Where did you find the documentation for the MERGE command? I have d/l'd
the _SQL Reference Volume 2_ from the IBM site and it doesn't show MERGE
as a statement (it goes from 'LOCK TABLE' straight to 'OPEN').

The real problem is I am getting the updates/addition to my real, almost
correctly designed (IMNSHO :-), database from several sources which use
different views of the same data. The data pertains to animals, and I
have separate tables for things like birth data, weaning data, genetic
fitness data, etc., since we almost never know all of the data for one
animal, or it doesn't pertain to a particular animal. The saving in
space/retrieval time is significant because the ultimate goal is to have
10^8 animals in the database. Unfortunately, my data suppliers see the
data differently, so there could be anywhere from 1 (massive) table
which would update each of my tables to a table set which is isomorphic
to my table set modulo column order. Since my data suppliers cannot
decide on a common unique identifier, I am using a generated field for
the identification of each animal and mapping the different suppliers
(not necessarily UNIQUE, especially over time) identifier to it. I do
this in an SQL procedure which seems to run forever. all of the
"dependent" tables use this same key. To make the problem even more
interesting each supplier presents pedigree data differently, some times
causing as many as 15 animals to be added to the main table for each
input record!

Which leads to another question: can I use the MERGE statement to update
a column which IS NOT NULL, or does it operate similarly to the COALESCE
function? From the use of SET in the statement, it would appear that
updates are possible. Also like UPDATE's SET operand, there can be
multiple attributes set in one statement, right?

Nov 12 '05 #5

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

Similar topics

3
4092
by: Daniel Pryde | last post by:
Hi there. I hope this isn't a stupid question to ask, but does anyone know how to print out a string without moving to a new line each time and simply updating the first line. An example would be,...
0
1916
by: HeroOfSpielburg | last post by:
hi, I know this is a much-travelled subject, but I was wondering what people's thoughts were on the bare minimum (and conversely the grand scheme) for augmenting standard memory references to...
0
396
by: Robert Stearns | last post by:
I loaded a flat file into an SQL table and verified the data. Now I want to move the data from the input table to the real table. I thought to use a SQL statement like: update is2.animals t1...
5
3501
by: Bill | last post by:
I have have two list boxes. One is a listing of all possible variables. We'll call this listbox A. The other is a listing of all the selected variables. We'll call this listbox B. If a person...
9
4657
by: Kevin Blount | last post by:
Here's the code I tried, and found it failed... <form runat="server" method="post" name="CreditCardForm" id="CreditCardForm"> <% foreach (object item in Request.Form) { if...
1
1960
by: Robert Hooker | last post by:
Hi All, After moving to VS2005, we've noticed that opening an existing (large) solution and being able to type code takes a lot longer than in VS2003. Typically, the IDE will open, and all the...
9
2967
by: Peter Webb | last post by:
I want to animate one object moving in front of another. I cannot re-render the background as the object moves, as it would be extremely time consuming. This is what I would like to do. I draw...
2
1654
by: anthony | last post by:
I have an old database which started out life in the Access 2 days! It's full of lots of stuff which I'm not convinced is relevant any longer. Would a good way forward be to create a new, blank...
3
4650
by: Avi | last post by:
Hi all, I have a web page with Multiline TextBox. Every 3 seconds I refresh the page and display all received messages in this TextBox. When the TextBox is updated (The Text property is set). ...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7319
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
5623
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,...
0
4702
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...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
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 ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
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...

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.