473,769 Members | 7,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

correlated update headache (db2 unix)

2 New Member
(aix 5.1, db2 8.1.6)

Consider this toy example:
--------------------
create table foo ( alpha int, beta int );

insert into foo ( 100, -1 );
insert into foo ( 200, -1 );
insert into foo ( 300, -1 );

update foo x set beta = ( select count(*) from foo y where y.beta >= 0 );
--------------------

I would swear I ran code like this ages ago,
and it generated smth like these results:
: alpha beta :
: 100 0 :
: 200 1 :
: 300 2 :

I expected something like this because the update
will evaluate each row in foo.
The first time it evaluates the nested-select,
all values of beta are negative, so the count(*) will
yield 0.

The 2nd time it evaluates the nested-select,
most values of beta are negative (one is zero),
so the count(*) should yield 1.

etc.


What I'm getting is:
: alpha beta :
: 100 0 :
: 200 0 :
: 300 0 :

Now I really do not care about the order of alpha: any permutation
would be fine, e.g.
: alpha beta : alpha beta : alpha beta :
: 100 2 : 100 1 : 100 2 :
: 200 1 : 200 0 : 200 0 :
: 300 0 : 300 2 : 300 1 :


Is there a query option or smth I can set to make db2/udb's
update work like this?
Thanks, John G.
Nov 16 '06 #1
1 1846
jgreve
2 New Member
Sorry, never mind. My memory was probably playing tricks on me. If I knew how to delete a thread, I'd kill this one.

Trying to read from a modified table in-flight is probably goes against some principle in sql's data model.

(Though if you do know of a way to do this, please tell me :-)
Nov 16 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

100
9103
by: Peter | last post by:
Company thought DB2 will be better than Oracle. The bottom line is when you do select, the system crash. I think it may take 4-5 years for DB2 to reach Oracle standard. Peter
0
15004
by: Murali | last post by:
Hi All I was reading thro the posting(s) of Thomas Kyte and his nifty approach to doing updates without the need for unnecessary correlated subqueries. An alternative to correlated subquery using this technique is: update ( select columnName, value from name, lookup
7
3372
by: CT | last post by:
Hi, This might seem like a basic question but I have some doubts, please humour me. I have a client-server application using java where each client on each machine needs to directly communicate directly with the database. Do I need a separate db2 connect on each such machine. Please advice.
1
6128
by: Mike L. Bell | last post by:
Query: update table1 t1 set end_time = ( select end_time from table2 t2 where t2.key1 = t1.key1 and t2.key2 = t1.key2 ) where exists
375
18186
by: rkusenet | last post by:
This article is very bleak about future of DB2. How credible is the author. http://www.eweek.com/article2/0,1895,1839681,00.asp
8
5107
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A WHERE EXISTS (SELECT 'X' FROM B, C WHERE B.COL1 = A.COL1 AND B.COL2 = A.COL2
3
49560
by: spartacus | last post by:
Hi, Does SQL support update to multiple rows where values coming from a sub-query? e.g insert into TABLE1 select column1, column2, column3 from TABLE2
3
10911
by: taru | last post by:
Env: DB2 UDB 8.1 on AIX We are executing a db2 sql stored procedure which is invoked from a java client. The stored procedure contains few select, insert and update statements. Using the DB2 snapshot and event monitor we are able to find the time taken for the stored procedure execution. We want to find what is the execution time for each
2
2203
by: benfly08 | last post by:
Hi, Folks. I got a scenario that cause me headache. Currently our company is using an AS/400 Server which run DB2 to hold all critical data(I called it remote site). I dont' have acess to this database. My local site use SQL Server. SQL Server uses DTS to transfer data from DB2 to its local database. Because of design issue, DB2 has 2 tables to contain the item information (like name, brand, categories), and SQL Server...
0
9423
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
10214
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...
1
9996
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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
8872
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...
0
6674
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
5304
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
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.