Re: Basic question about structuring SQL - Mailing list pgsql-general

From David G. Johnston
Subject Re: Basic question about structuring SQL
Date
Msg-id CAKFQuwY5RSsmth4kZxCasdAvc=joAqguB6g7Ut+TyZz6C3=aFQ@mail.gmail.com
Whole thread Raw
In response to Basic question about structuring SQL  (Robert Inder <robert@interactive.co.uk>)
List pgsql-general
On Tue, Jul 7, 2020 at 4:41 AM Robert Inder <robert@interactive.co.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.

pgsql-general by date:

Previous
From: Sebastien Arod
Date:
Subject: Re: Is postgres able to share sorts required by common partition window functions?
Next
From: Michael Lewis
Date:
Subject: Re: Is postgres able to share sorts required by common partition window functions?