Search Postgresql Archives

Re: Basic question about structuring SQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2020-07-07 at 12:40 +0100, Robert Inder wrote:
> NOW, I want to do the same for a BIGGER task.
> BUT I realise that if I create bigger-task.sql like this...
>    BEGIN;
>       <<preparatory  operations>>
>    \i do-something-useful.sql
>       <<tidy up code>>
>    COMMIT;
> ...the COMMIT inside "do-something-useful.sql" closes the transaction started in "bigger-task.sql"
> So I can get some things committed even if other things (in tidy-up) fail.
> 
> So how SHOULD I tackle this? 
> PostgreSQL does not do nested transactions (right?)

You can use subtransactions.

In the inner scripts, don't use BEGIN, but SAVEPOINT <name>.
Instead of ROLLBACK in the inner script, use ROLLBACK TO SAVEPOINT <name>.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux