Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1trg6j-007GTN-G9 for pgsql-general@arkaria.postgresql.org; Mon, 10 Mar 2025 16:36:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1trg6i-00F6YY-8T for pgsql-general@arkaria.postgresql.org; Mon, 10 Mar 2025 16:36:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1trg6h-00F6YQ-Ts for pgsql-general@lists.postgresql.org; Mon, 10 Mar 2025 16:35:59 +0000 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1trg6e-0024Nw-1H for pgsql-general@lists.postgresql.org; Mon, 10 Mar 2025 16:35:59 +0000 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-6fda22908d9so33115197b3.1 for ; Mon, 10 Mar 2025 09:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741624556; x=1742229356; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+Di7x7XjffoQQdSXmVWVxcvvOZSAF3RKHJCert8FEpc=; b=IPMuiW0SG2tJjadTKWgS6K57KLGYXy6hkcI6g2mltmv3Fgvs8jHb871wJYq0CxtQSg kSqau6WLtC4Pj/BP3S57u6yeBHOHjyS7W9PWKRYqcs5WUozHovEn/0lkfmHY+aHC/6iv gXpv0YZkt5NdcjcNs+iMngQPA3J20By2iIfF/Ibw5Ji/VWYxWzrEaVgQoiMpnzuFonp/ g7SHGwWmeN09MJMzAaWG8ekLRQHOUEDhpWmkj4VGuWKDf3nJhY2Jmi0tzzsaBXgK3Gzh 4H7sNyBT1zeElTD5P0QUBZ7MQ3GIRFWWFkC1fCyEKs061LXGzLvDvBMF87i8xTkagXLy vEDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741624556; x=1742229356; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+Di7x7XjffoQQdSXmVWVxcvvOZSAF3RKHJCert8FEpc=; b=PHVBa2p+6cqnvvGyUvgDT9nchzp/hlJuBz0P7SYmA/oWLxjjj9d3tzO47rIqUoQcn/ Gps9sB3OdCP+8opVuWZ3WFKsKv9qbpsUGS1q75uwSXygnC43C069WPKWxq4WI2YcBVOC yGrSMhhQJ6v0NnNG91W6m7B/wtLu4auY7VuGzZBVN6vdXBlcbv3/hfcaYbB6Srj3C6IF qEtnKoobyFRXYyLdsjL8hBAHrQ2lM+JXSZHQXyst4KmRsJWctC6U+YKV2YdCFiU7scOm 8mpC8YuiiE4hj12e9Kbb4s8JqxEvjmbKR6i4u4MX0DmzPugAvneiLS4hpVLAS8tSCU2G kraw== X-Gm-Message-State: AOJu0YwWYhw6TOWxziWxWpcHsuaB55XdsmAEDinwC7HOgxzQHWJNffCV 1lmfd8hz3ySE2joih33RgPJpjvZeFbHezbihfFtFAeIHSTp1dWyXwMvIVk9M8nDWyHO0YCX4aD6 sflvnbGpCM8qg6yrJEvQXmU0OtyhCCg== X-Gm-Gg: ASbGncv4c6Ple2rzG+dkSujCXDK+WoTumD/gRAZzB1XXdI9gTHgy+8l1MMYY8E1VxD6 gzR1UAY9Fw870Tlyj0dRjjZe6e0JL9PmYG7HXDYDtEACpUth/+76SklmWfq3StQFOHfzvFP4h5l 8Yll0lsPj2MnhZXaK+t2w6uIdd4ygL6qudbN8Iogksn4NbOb1nIWVBdE4YU9W6fXZKYdFIxaA= X-Google-Smtp-Source: AGHT+IGB7gGz2O6HUc2gmiqUWsEaxbnL68Uf5UoC2meBVwU+3mwsh30gOUFNgZ0qjrdKQaKjtFxyghKwxaFdRg+4bBc= X-Received: by 2002:a05:690c:9c09:b0:6ef:4ed2:7dfe with SMTP id 00721157ae682-6febf3b4f46mr201348617b3.31.1741624556114; Mon, 10 Mar 2025 09:35:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Igor Korot Date: Mon, 10 Mar 2025 11:35:45 -0500 X-Gm-Features: AQ5f1JoOlr0yDI2PpBrUTb0xV2whf86Etc5STc2Ec0v3sieruJ8HCsr3tSuek80 Message-ID: Subject: Re: Big script execution To: Laurenz Albe Cc: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000ffdb8e062fff90dc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ffdb8e062fff90dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Laurenz, On Mon, Mar 10, 2025, 11:31=E2=80=AFAM Laurenz Albe wrote: > On Mon, 2025-03-10 at 16:42 -0500, Igor Korot wrote: > > I am trying to execute a huge script (~40K lines) that will populate > > my database. > > > > The script starts with "BEGIN TRANSACTION" and will end > > with "COMMIT". > > > > however I'd like to rollback if there is an error encounter. > > > > When I execute it from the Terminal I do use > > > > -v ON_ERROR_STOP=3D1 > > > > but I'd like to rolback the transaction so it starts a fresh every time= . > > > > Is there some kind of > > > > ON ERROR ROLLBACK > > > > command I can put inside the script? > > That happens automatically: if you are running the whole script in a > single transaction, any error will make the whole transaction roll back. > Will the tables also be deleted? The CREATE TABLE statements are part of this big transaction. Thank you. > Yours, > Laurenz Albe > --000000000000ffdb8e062fff90dc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, Laurenz,

On Mon, Mar 10, 2025= , 11:31=E2=80=AFAM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
On Mon, 2025-03-10 at 16:42 -0500, Igor Korot wrote:
> I am trying to execute a huge script (~40K lines) that will populate > my database.
>
> The script starts with "BEGIN TRANSACTION" and will end
> with "COMMIT".
>
> however I'd like to rollback if there is an error encounter.
>
> When I execute it from the Terminal I do use
>
> -v ON_ERROR_STOP=3D1
>
> but I'd like to rolback the transaction so it starts a fresh every= time.
>
> Is there some kind of
>
> ON ERROR ROLLBACK
>
> command I can put inside the script?

That happens automatically: if you are running the whole script in a
single transaction, any error will make the whole transaction roll back.

Wil= l the tables also be deleted?
The CREATE TABLE state= ments are part of this big transaction.

Thank you.


Yours,
Laurenz Albe
--000000000000ffdb8e062fff90dc--