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 1pqyLd-0007iK-Qt for pgsql-general@arkaria.postgresql.org; Mon, 24 Apr 2023 15:43:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pqyLc-0005nn-La for pgsql-general@arkaria.postgresql.org; Mon, 24 Apr 2023 15:43:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pqyLc-0005nd-Aw for pgsql-general@lists.postgresql.org; Mon, 24 Apr 2023 15:43:24 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pqyLV-001eSu-P3 for pgsql-general@lists.postgresql.org; Mon, 24 Apr 2023 15:43:23 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 339B6320093D; Mon, 24 Apr 2023 11:43:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 24 Apr 2023 11:43:16 -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= 1682350995; x=1682437395; bh=G9/MzOsyg9lVcBl/2rZ6QmFO8o5pwXFtM+3 xtEw9cSU=; b=qDxPzLvwpMNh4m+3EkLjTU7lTJU02j3dfHhM4ZK4aqn2OHYijk6 JFDob+/3opIQagZPMvaH++aluwiaWo3TYVGmuqzN/n7Ibrh8PGAjKePAHRw8f6af VdyTC1OR6A4q9ssP+S/q9sGd2WHkrQ9BZ7U4TaPsssmW0amzMMfgYyrPoaLeR84D m9e5qTmozKOzTY9etm8UWuP8ITFs9A0y5Eaa7WJ7BhuWz0lo9JaNY9r02+vZj3HE 4n8WlxfxQDl8kYUqj8cPCD+Ca6qbwNYFHPr8V21tuysQPb3il9nMYt7Oiozau0lt QESNzFFL9hIoOLwwnr/2e4I9rb7LSDDMlxQ== 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=1682350995; x= 1682437395; bh=G9/MzOsyg9lVcBl/2rZ6QmFO8o5pwXFtM+3xtEw9cSU=; b=D 6/JnojE55tkut4HNr2XK6BpJRl6wPgEHbbDRMkgnmlomcas0/1X8cqcRoD3jpB1P mWEtDPSb3sgZrAN0T2ixzdQqb3kciK22z2m8Ra9sxK8nhUhUJ6LQnMV9rCE2UkZ6 xd1Gq7kbKwULHbs5GKGytyfnK35K0NfJDPSm6f+AI+c660ljGct8gJ5f/WBLhi40 Hf0WvsjuR1rY17Svej7fekXi7BAwXqGxFD+z3Lo/V6KVM9XCVYqqnQb+u3iI0P4V 3hWhZEbzuOlkDGehfdjyeRD3Vh+LazAD4sgwHciXXa21MfIM0Tsnu9S0Tf6LBHsp CtPNG7z8wH5ywZsBw1z8A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedutddgleduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudfgueelge evfffhgeeljeehhfettdegieelgefgheefffefveegjedtueetffdtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvh gvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 24 Apr 2023 11:43:14 -0400 (EDT) Message-ID: Date: Mon, 24 Apr 2023 08:43:14 -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 To: Siddharth Jain , pgsql-general@lists.postgresql.org References: From: Adrian Klaver 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: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 > > thanks. > > S. -- Adrian Klaver adrian.klaver@aklaver.com