pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wen Yi <wen-yi@qq.com>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: My question about the transaction
Date: Thu, 19 Oct 2023 19:36:26 +0800
Message-ID: <tencent_9534EB34569D4C532043E39EDC7AA40B5D09@qq.com> (raw)

Hi community,
I am learning the transaction of the postgresql, and I try to test using these:


######



terminal 1:



postgres=# select * from t;
 number 
--------
      1
(1 row)

postgres=# update t set number = 2;
UPDATE 1
postgres=# select * from t;
 number 
--------
      2
(1 row)

postgres=# select * from t;
 number 
--------
      2
(1 row)

postgres=# 



######


terminal 2:


postgres=# create table t (number integer);
CREATE TABLE
postgres=# insert into t values (1);
INSERT 0 1
postgres=# begin;
BEGIN
postgres=*# insert into t values (2);
INSERT 0 1
postgres=*# select * from t;
 number 
--------
      2
      2
(2 rows)

postgres=*# rollback;
ROLLBACK



My question is, in my view, the transaction model should make sure that when one on-process transaction don't commit itself, the data on this transaction shouldn't can be modified by other transaction(I the single-statement also be treated as a simple transaction), but why the update works?(I think terminal 1 will block until the terminal 2's transaction commit or rollback).
Can someone share you opinion to me?
Thanks in advance!


Yours,
Wen Yi

view thread (5+ messages)  latest in thread

Message-ID: <tencent_9534EB34569D4C532043E39EDC7AA40B5D09@qq.com>
Permalink:  ../tencent_9534EB34569D4C532043E39EDC7AA40B5D09@qq.com/
Also on:    postgresql.org/message-id/tencent_9534EB34569D4C532043E39EDC7AA40B5D09@qq.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: wen-yi@qq.com
  Subject: Re: My question about the transaction
  In-Reply-To: <tencent_9534EB34569D4C532043E39EDC7AA40B5D09@qq.com>
  References: <tencent_9534EB34569D4C532043E39EDC7AA40B5D09@qq.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox