SQL Basics
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old July 22nd, 2009, 12:04 AM
dbuser_01 dbuser_01 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 1 dbuser_01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 5 sec
Reputation Power: 0
Co related update query

Hi,
I am trying to use an update corelated query which is expected to do the following:
The outer update query updates a field and the sub query based on the outer query fetches, using a select, the updatable field from a previous row in the table. Based on what is returned by the previous row the inner query computes on this field and passes the same to the outer query for updation. And this continues for all other rows meeting a certain criteria.
In short i am using the corelated sub query to update an updatable field whose value is calculated and updated in the same corelated query in some other iteration.

Following is the query i am using in postgres:
update sample_tab2 a set stock=initialstock + (percent/100)*(select b.stock from sample_tab2 b
where a.region=b.region and b.period=(a.period - cast('1 week' as interval) * 1)) where region='Asia';

The result of this is:
if the stock field has some initial values in it then it calculates those values and updates the same field for some other row but if the stock field's value is calculated in the same query in some other iteration and used in some other row for updation then it doesnt get the latest value, as updated in the corelated query, and updates with old value that existed before the corelated query executed.

Although I am using postgres but my question is general:
Does a corelated update sub query update the fields in the DB only after the execution of the whole query this includes all iterations of the corelated query and during this time of execution it maintains a cache where the fields' new updated values are kept. So if the inner query queries the fields updated by the corelated query, within the same co related query's scope then it would get old values. And these values can be seen only after the query has executed completely. I hope it makes sense...
If what i have stated above is true then what can be the solution for this?
Else please share your views and possible solutions to the problem. A solution may exist using cursors but I want to explore if I can do the above expected using just one query.

Thanks in advance.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Co related update query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek