Are subselects treated as atomic single commands?

From: "Thomas Chille" <thomas(at)chille(dot)de>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Are subselects treated as atomic single commands?
Date: 2004-11-24 16:29:05
Message-ID: 004501c4d242$b7e46690$500a0a0a@spoon.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

the docu about the Read Committed Transaction Isolation Level pointed out: "... The point at issue
here is whether or not within a single command we see an absolutely consistent view of the
database.".

Because i dont want to use the Serializable Transaction Isolation Level or table locks if it not
necessary i have one question:

Would the insert command with that subselect treated as one single command and can i so prevent a
race condition between multiple function calls?

CREATE OR REPLACE FUNCTION "public"."count_parameter" (name, integer)
RETURNS "pg_catalog"."void" AS'
BEGIN

INSERT INTO parameter (parameter_name, parameter_value)
SELECT $1, $2 WHERE (
SELECT COUNT(*) = 0 FROM parameter WHERE parameter_name = $1
);
IF NOT FOUND THEN
UPDATE parameter SET parameter_value = parameter_value + $2
WHERE parameter_name = $1;
END IF;

RETURN;

END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

best regards,
thomas

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2004-11-24 16:30:03 Re: PostGreSQL upgrade failed (Debian Packages), need advice...
Previous Message Ben 2004-11-24 16:27:17 Re: Nesting Stored Procedure Calls