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 1pqyNO-0007ob-Cb for pgsql-general@arkaria.postgresql.org; Mon, 24 Apr 2023 15:45:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pqyNN-0001M0-Af for pgsql-general@arkaria.postgresql.org; Mon, 24 Apr 2023 15:45:13 +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 1pqyNM-0001Lr-W8 for pgsql-general@lists.postgresql.org; Mon, 24 Apr 2023 15:45:12 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pqyNJ-004p1s-NP for pgsql-general@lists.postgresql.org; Mon, 24 Apr 2023 15:45:12 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 1F76A32005CA; Mon, 24 Apr 2023 11:45:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 24 Apr 2023 11:45:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1682351104; x=1682437504; bh=oMprWiZ2eyuHPMkBteleyLzv+gdJwfdDLQZ n2AX28vM=; b=kuz/8jN9DBnxFWhX999UszLsqFOD6dknBp7TUnfG9GMvXyOPSzn sdX0upuL1hex1tmDrmHQL6PUckjcJiCCiF0Jod/QZNCs2RJcvuFKTZGT4IR9z0wc AhZd2F26QVnViZaNKKdWU3Zx5+FYPJaTaU1Hs6D4J45IG1ENfRNx+0JmNneVGNku gGaARTXFxfw5+cwYFeqaekxpoukBYoIaZYLlLiUj1T9eU7smQ+wZPhnO6WSshPZe rS42Nuy+N8eDXyrWQZdP1QCd9g6CPZqydKh+AxxQYIdtUSH5s643goM4wXl1MHxr RV7/EGE/jy+8Xa4Ma+U4cEpj9dyTWjE3NVw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1682351104; x= 1682437504; bh=oMprWiZ2eyuHPMkBteleyLzv+gdJwfdDLQZn2AX28vM=; b=H sHdegyrWCYU22MNxT8TO2dZxaTlWVEjt6SqrEoPG3cM6I0H8dEAH1acHP2h20wpT cTAFVhPl46GDFyuoxYgy789UvsU5rZp0pON7nCmjM5snabV1/akpTyTOuUF/M76n m0GzN0bFMg+zXpDol10SAtdjRnjbfGkF5mHFay0WUPW0qvQMrWReMTUTwluUVnSE TCD7DtwX/oCVCHLY6XkM6Piq740E1UAnLpeuhhK0dbkfG07Zk/GPiruD/YBEeCWc /MpdEFNPHr9bn5KcSny0Xwga/nIP+1WX7q+5LFoNfk0Xh8SW78MMVYriWWORbcCA 2saOKCb48jsJzPd+YbzIg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedutddgleduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuhffvfhgjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepleejvdelgf elgeejgeejiefhtdejhfehgeeghedvjeejffefvefhffdtgefhffejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvh gvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 24 Apr 2023 11:45:04 -0400 (EDT) Message-ID: <89614320-852e-ce8d-7b01-2eff0e537e09@aklaver.com> Date: Mon, 24 Apr 2023 08:45:03 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: what happens if a failed transaction is not rolled back? Content-Language: en-US From: Adrian Klaver To: Siddharth Jain , pgsql-general@lists.postgresql.org References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/24/23 08:43, Adrian Klaver wrote: > On 4/24/23 08:37, Siddharth Jain wrote: >> Hi All, >> >> i understand when writing application code, we should rollback a >> transaction that fails to commit. this is typically done in the catch >> block of a try-catch exception handler. but what if the developer does >> not rollback the transaction? what happens in that case? >> >> note that i am not asking: what happens if a transaction is not rolled >> back? >> i am asking: what happens if a /failed/ transaction is not rolled back? >> >> failed transaction = you try to commit it but get an exception back >> from the database. > > In Python: > > import psycopg2 > con = psycopg2.connect("dbname=test host=localhost  user=postgres") > cur = con.cursor() > cur.execute("select 1/0") > DivisionByZero: division by zero > > cur.execute("select 1") > InFailedSqlTransaction: current transaction is aborted, commands ignored > until end of transaction block Forgot to add. To get past above: con.rollback() cur.execute("select 1") > > > >> >> thanks. >> >> S. > -- Adrian Klaver adrian.klaver@aklaver.com