From: Igal @ Lucee.org <igal@lucee.org>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: DDL and DML in a transaction
Date: Wed, 31 Jul 2019 11:38:39 -0700
Message-ID: <28ca745e-f459-95bd-bf80-7d907b65b9cf@lucee.org> (raw)
I am trying to change a text column into a numeric one in a large table.
My idea was to add a new column, update it, drop the old column, and
rename the new one to the old name. I am hoping that that would make it
faster and minimize locking time though I'm not sure that it would.
I am therefore trying to execute the following but I'm getting an error
that the new column does not exist:
begin;
alter table some_table
add column if not exists amount_num numeric(30,12);
update some_table
set amount_num = amount_text::numeric(30,12);
alter table some_table
drop column amount_text;
alter table some_table
rename column amount_num to amount_text;
alter table some_table
drop column amount_num;
commit;
end;
Am I missing something? Is this supposed to work?
Would it have less locking than simply altering the column?
Thanks,
Igal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: igal@lucee.org
Subject: Re: DDL and DML in a transaction
In-Reply-To: <28ca745e-f459-95bd-bf80-7d907b65b9cf@lucee.org>
References: <28ca745e-f459-95bd-bf80-7d907b65b9cf@lucee.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox