473,569 Members | 2,522 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.col or
;

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 2624
update is2.animals t1 join nullid.nalfherd _in t2
on t1.prefix = t2.reg_prefix
and t1.regnum = t2.regisno
set t1.color=t2.col or
; 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.col or;

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.col or
; 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.col or;

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.col or
;


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.col or;

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.col or
;


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.col or;

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
4097
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, if I wanted to have a percentage progress counter that was constantly updating. I'm unsure how to do this without printing to a brand new line. Any...
0
1923
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 handle moving objects around in memory (as is needed in compaction algorithms associated with 'moving collection' aka 'copy collection'). There are a...
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 join nullid.nalfherd_in t2 on t1.prefix = t2.reg_prefix and t1.regnum = t2.regisno set t1.color=t2.color ;
5
3509
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 double-clicks on one of the variables in listbox A it "moves" it to listbox B. What is going on behind the scenes is that the table that holds all...
9
4660
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 (item.ToString().IndexOf("__") != 0) { //Response.Write(item + " = " + Request.Form +
1
1965
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 windows will appear, but then the hour glass will flick on and off for about 1 minute. If the "Pending Checkins" window is open, I can see a message...
9
2978
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 the background to a Graphics object, copy it, draw the front object on the original, render it to the screen, then reload the copy (Clone?) of the...
2
1657
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 database in Access 2007 and then import the existing objects, re-create the relationships etc? That way I can just bring in the stuff that's currently...
3
4656
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). The vertical scrollbar is flickering (moving up and down and the scrollbar "square" is starting big and shrinks when the TextBox is filled). ...
0
7701
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
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. ...
1
7677
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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...
1
5514
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...
0
5219
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
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...

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.