473,765 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

order of row processing affects updates

Hi all!
consider the following table

table a (id int primary key)
and a particular instance of it:
id
------------------------
5
6

now update a set id = id +1;
fails if the executor processes row with 5 first.
This means that the query will succeed sometimes and fail at other times
(when it processes 6 first).
Are there any workarounds to this?
Basically what we would like to do would be something like doing constraint
validations only at the end of execution of an update query, instead of
after every row update.

to see why sometimes this query might work, run the following commands:

create table a (id int primary key);
insert into a values (6);
insert into a values (5);
update a set id = id +1;

basically we would like to see uniformity in execution. Either the query
should always fail or always succeed.
Are there any standards on this?

any info will be helpful
paraM

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #1
3 1254
On Sun, 2004-09-19 at 08:37 -0500, Pa************* @trilogy.com wrote:
table a (id int primary key)
and a particular instance of it:
id
------------------------
5
6

now update a set id = id +1;
fails if the executor processes row with 5 first.
Basically what we would like to do would be something like doing constraint
validations only at the end of execution of an update query, instead of
after every row update.

does it fail even if it's in a
BEGIN
UPDATE ..
COMMIT
?

--
Marius Andreiana
Galuna - Solutii Linux in Romania
http://www.galuna.ro
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
On Sun, 19 Sep 2004 08:37:10 -0500, Paramveer.Singh wrote:
Hi all!
consider the following table

table a (id int primary key)
and a particular instance of it:
id
------------------------
5
6

now update a set id = id +1;
fails if the executor processes row with 5 first.
This means that the query will succeed sometimes and fail at other times
(when it processes 6 first).
Are there any workarounds to this?
Basically what we would like to do would be something like doing constraint
validations only at the end of execution of an update query, instead of
after every row update.

to see why sometimes this query might work, run the following commands:

create table a (id int primary key);
insert into a values (6);
insert into a values (5);
update a set id = id +1;

basically we would like to see uniformity in execution. Either the query
should always fail or always succeed.
Are there any standards on this?


What is the logic for changing the PK?

One option is a SELECT INTO statement. The id can be incremented during
the statement.

Nov 23 '05 #3
Pa************* @trilogy.com writes:
Hi all!
consider the following table

table a (id int primary key)
and a particular instance of it:
id
------------------------
5
6

now update a set id = id +1;
fails if the executor processes row with 5 first.


Well the correct way to make this always work would be to make the unique
constraint deferrable and set constraints to be deferred. However Postgres
doesn't support deferring unique constraints.

I don't think there's any practical way to guarantee the ordering of the
update. You could cluster the table on the unique index which would guarantee
it will fail. But clustering is a slow operation and it would have to be done
before every update like this.

To make it work I think the usual work-around is to update the ids to be in a
different range, and then update them to the final values. Something like:

BEGIN;
UPDATE a SET id = -id;
UPDATE a SET id = -id + 1;
COMMIT;
--
greg
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #4

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

Similar topics

5
2527
by: pooh | last post by:
I have a situation where the order of my cpp files in my g++ compile command line affects the program. Here is a simplified example: g++ -Wall -o test a.cpp b.cpp compiles, links and runs fine. g++ -Wall -o test b.cpp a.cpp
5
1504
by: Joe Reazor | last post by:
I've got an asp.net page that has approximately 1,440 controls on it. You must think I'm crazy, but we need to have the page organized in this fashion. As you can imagine, the page takes a very long to to process, on the order of 20-30 seconds, even though only a small number of the controls are generally visible at once it still has to process all the controls on the page for ever page load. I have been researching ways to speed up the...
4
1584
by: Fao, Sean | last post by:
I'm trying to show an animated image temporarily while the web server is processing a long request. I attempted to use a combination of CSS styles and JavaScript to temporarily hide or show only appropriate portions of the page (e.g. hide the data and show an animated "processing" image while the server is doing work), however, it's not exactly working out the way I had hoped. What's the best way to accomplish this task? Thank you in...
16
2450
by: mdh | last post by:
May I ask the group the following: (Again, alas , from K&R) This is part of a function: while ( ( array1 = array2 ) != '\0' ); /* etc etc */ Is this the order that this is evaluated? -> array2 is assigned to array1 ....???? the reason being it is
4
1602
by: Mike | last post by:
Hi everyone, I need to develop a new asp.net 2.0 web app that has to allow a client the ability to work with an internal adviser on the same document (an offer) at the same time. I am not sure how to allow two persons working on the same application and changes be reflected to both browsers. For sharing the data, I could set up a DB, apply a unique ID that they both would use to manipulate the common data. The problem that I have is with the...
1
1244
by: perlguru | last post by:
I wanted to know about the affects of changes done in US DST on FSF library. My major concentration is on GSL. Will GSL be affected ? If so, Is there any patch for this ? Is there any article on web, showing which all FSF libraries are affected ?
54
3941
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of parentheses. 1) "The order of evaluation of subexpressions is determined by the precedence and grouping of operators."
7
1370
by: new to c | last post by:
Hi! I write the 2 codes int i; i = sizeof(long int); printf("%i", i); i = sizeof(int long); printf("%i", i);
7
2415
by: Norman Scheffler | last post by:
Hello, I wrote an update trigger to detect the names of the updated columns of a table using the UPDATED(columnName) function. In a stored procedure I wrote code to update user information with given parameters. Update daUser SET strFirstName = @vstrFirstName, strLastName = @vstrLastName,
4
5161
by: Alfredo73 | last post by:
Hi, I am using Visual Basic 2008 to create some databases. It reads data from textfiles and puts them in SQL databases. After the user presses the Process button I would like to give the user to get some feedback of the process simply by for example label1.text += "Processing File 2". But during the process no Screen Updates are made...only after all databases are processed and VB.net is waiting for new user response it updates my...
0
9568
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
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...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8831
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
6649
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
5275
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
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.