Re: ALTER TABLE atomicity with sub-commands - Mailing list pgsql-docs

From Erik Wienhold
Subject Re: ALTER TABLE atomicity with sub-commands
Date
Msg-id ylkb3aooldasy5qil6rgq4hqmdpitrw57jtgyybj7yngdmcrwu@s3knmnbzbldc
Whole thread Raw
In response to ALTER TABLE atomicity with sub-commands  (PG Doc comments form <noreply@postgresql.org>)
List pgsql-docs
On 2024-04-02 16:40 +0200, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
> 
> Page: https://www.postgresql.org/docs/15/sql-altertable.html
> Description:
> 
> It is not entirely clear (to me) that ALTER TABLE statements with
> comma-separated sub-commands are atomic. Despite of saying "perform X
> actions in one operation" in one of the examples, it is not explicitly said
> that the operation will be rolled back if one of the sub-commands fails. 
> 
> From the examples, we have:
> 
> ALTER TABLE distributors
>     ALTER COLUMN address TYPE varchar(80),
>     ALTER COLUMN name TYPE varchar(100);
> 
> Will the `address` column type change rollback if the `ALTER COLUMN name
> TYPE varchar(100)` subcommand fails?
> 
> Currently reading the docs for version 15.

Yes, ALTER TABLE, like all statements, is one atomic change.

From BEGIN[1]:

    By default (without BEGIN), PostgreSQL executes transactions in
    “autocommit” mode, that is, each statement is executed in its own
    transaction and a commit is implicitly performed at the end of the
    statement (if execution was successful, otherwise a rollback is
    done).

[1] https://www.postgresql.org/docs/15/sql-begin.html

-- 
Erik



pgsql-docs by date:

Previous
From: PG Doc comments form
Date:
Subject: ALTER TABLE atomicity with sub-commands
Next
From: Rajan Pandey
Date:
Subject: [MASSMAIL] Postgres_FDW doc doesn't specify TYPE support in Remote Execution Options