Re: Atomicity?

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Naz Gassiep <naz(at)mira(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Atomicity?
Date: 2006-08-28 19:59:51
Message-ID: 44F34B37.9060708@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Naz Gassiep wrote:
> I am getting an error that I think I understand, but that I didn't think
> should happen.
>
> Below is the output from psql that I am getting to trigger this error.
> If the violation of the constraint really is being caused WITHIN the
> query, doesn't that violate the principle of atomicity? I.e., operations
> and entities should be considered a single entire construct rather than
> a collection of smaller, discrete parts. Or do I have my understanding
> all wrong?
>
> In any case, how do I get around this problem?

If you do not specify the beginning of a transaction, all statements are
run within their own transaction.. e;g:

Your example actually means:

begin;

> conwatch=# UPDATE replies SET rgt = rgt + 2 WHERE postid = 18 AND rgt >=
> 11;

commit;

begin;
> conwatch=# UPDATE replies SET rgt = rgt + 2 WHERE postid = 18 AND rgt = 14;
commit;

What you want is:

begin;

> UPDATE 1
> conwatch=# UPDATE replies SET rgt = rgt + 2 WHERE postid = 18 AND rgt = 13;
> UPDATE 1
> conwatch=# UPDATE replies SET rgt = rgt + 2 WHERE postid = 18 AND rgt = 12;
> UPDATE 1
> conwatch=# UPDATE replies SET rgt = rgt + 2 WHERE postid = 18 AND rgt = 11;
> UPDATE 1
> conwatch=#

commit;

Joshua D. Drake

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

--

=== The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive PostgreSQL solutions since 1997
http://www.commandprompt.com/

In response to

  • Atomicity? at 2006-08-28 19:23:50 from Naz Gassiep

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Naz Gassiep 2006-08-28 20:00:29 Re: Atomicity?
Previous Message Peter Eisentraut 2006-08-28 19:46:00 Re: Atomicity?