Re: Basic question about structuring SQL

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Robert Inder <robert(at)interactive(dot)co(dot)uk>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Basic question about structuring SQL
Date: 2020-07-07 15:03:38
Message-ID: CAKFQuwY5RSsmth4kZxCasdAvc=joAqguB6g7Ut+TyZz6C3=aFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 7, 2020 at 4:41 AM Robert Inder <robert(at)interactive(dot)co(dot)uk>
wrote:

> So how should I structure my chunks of SQL so that I can have "safe"
> (all-or-nothing) blocks,
> AND use them from within one another?
>

While there are more advanced constructs that may aid here I would suggest
just following two rules:

top-level scripts handle transactions - usually just a single BEGIN/COMMIT
at the top/bottom of the script respectively. These are scripts you are
allowed to name on the psql command line.
support scripts don't handle transactions - these are scripts you include
into the main script with \i or \ir

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Lewis 2020-07-07 17:24:01 Re: Is postgres able to share sorts required by common partition window functions?
Previous Message Sebastien Arod 2020-07-07 15:01:20 Re: Is postgres able to share sorts required by common partition window functions?