473,386 Members | 1,823 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,386 software developers and data experts.

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 2596
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.