Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZzc9-0004qi-9J for psycopg@arkaria.postgresql.org; Mon, 11 Oct 2021 18:01:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mZzc6-0002Dn-DQ for psycopg@arkaria.postgresql.org; Mon, 11 Oct 2021 18:01:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZzc5-0002Df-Ty for psycopg@lists.postgresql.org; Mon, 11 Oct 2021 18:01:26 +0000 Received: from hedgehog.birch.relay.mailchannels.net ([23.83.209.81]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZzby-0004rn-JJ for psycopg@postgresql.org; Mon, 11 Oct 2021 18:01:25 +0000 X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 971F87618AC for ; Mon, 11 Oct 2021 18:01:14 +0000 (UTC) Received: from lu-shared04.cpanelplatform.com (unknown [127.0.0.6]) (Authenticated sender: cp7oy65bvo) by relay.mailchannels.net (Postfix) with ESMTPA id 091BF761BA8 for ; Mon, 11 Oct 2021 18:01:13 +0000 (UTC) X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from lu-shared04.cpanelplatform.com ([TEMPUNAVAIL]. [107.189.4.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.114.12.82 (trex/6.4.3); Mon, 11 Oct 2021 18:01:14 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: cp7oy65bvo|x-authuser|paolo@paolodestefani.it X-MailChannels-Auth-Id: cp7oy65bvo X-Stretch-Trade: 74ceac92086fd381_1633975274395_2414770556 X-MC-Loop-Signature: 1633975274395:4200555954 X-MC-Ingress-Time: 1633975274395 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=paolodestefani.it; s=default; h=Content-Transfer-Encoding:Content-Type: Message-ID:Subject:To:From:Date:MIME-Version:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=GTcckPizt3rnyiHNdnnrcRDYazRNc7nHIEJ13th1j0o=; b=xVDjKV/NpZXcn94XtWW2GJD777 TFiw/XkbP5xhZjkYC+v3WQJeZaDz9up5fWUwJ+7hhu0WJUzyJJJiKqb5klu/hPf4QcyYbtX0Wh3gX EvOgPh/Sabu7Sa1fZ8hdrHLKgEwqcrU1qxV+YV0XdJsiuCkMK/+qutP+Rt5qnmhe5Uo/DmiE4eUsq pSmrAZJbbd6gBcIz2E6RdlJmFqX9LMPSn9WcrIpIJSpmzQ4KBDabRklGH3eIi60L1M9F9K6b7uq8i /TG3MKKa0hzISCWNwJ/pzgkJW+rpERqHCeA4Iyj82EctYvZuwyZPSn62M+UL8VIPXNX1+56NyYYMx zFFqv5Ew==; Received: from [::1] (port=50204 helo=lu-shared04.cpanelplatform.com) by lu-shared04.cpanelplatform.com with esmtpa (Exim 4.94.2) (envelope-from ) id 1mZzbp-00AZRQ-Lq for psycopg@postgresql.org; Mon, 11 Oct 2021 20:01:09 +0200 MIME-Version: 1.0 Date: Mon, 11 Oct 2021 20:01:09 +0200 From: Paolo De Stefani To: Psycopg Subject: psycopg3 transactions User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: paolo@paolodestefani.it Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-AuthUser: paolo@paolodestefani.it List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi all In psycopg3 i read and understood the new transaction management behaviour. With the use of context managers i have to do something like this: con = psycopg.connect() with con.transaction(): with con.cursor() as cur: cur.execute("INSERT INTO table VALUES (1, 2, 3);") and this works as expected. But if i don't need a transaction because i don't need to commit anything i can do something like this: with con.cursor() as cur: cur.execute("SELECT * FROM table;") BUT if a do a select without a transaction the next command that require a transaction don't works until i do a specific commit with con.transaction(): with con.cursor() as cur: cur.execute("DELETE FROM table;") the delete is effective only for the current connection, i mean other db user continue to see the without the delete command modifications Looks like the previous select statement (uncommited) block following delete statement even if i use the with con.transaction() statement. If a do a con.commit() everything works as expected. That means i need to use a transaction even for a select statement. I can't use autocommit connection in my application. Is it correct or am i losing anything ??? -- Paolo De Stefani