Re: Long running update

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Long running update
Дата
Msg-id 9040.1129484814@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Long running update  ("Andrew Janian" <ajanian@scottrade.com>)
Список pgsql-general
"Andrew Janian" <ajanian@scottrade.com> writes:
> If I cancel the update then I can drop the new column, rename the old
> column, do a vacuum, and then I should be left with what I started with,
> right?

Right.

> How can I expand that column without using this query?

Basically you want to alter the pg_attribute.atttypmod field for the
column.  Here's an example:

regression=# create table mytable (mycolumn varchar(10));
CREATE TABLE
regression=# UPDATE pg_attribute SET atttypmod = 25 + 4
regression-# WHERE attrelid = 'mytable'::regclass
regression-#   AND attname = 'mycolumn';
UPDATE 1
regression=# \d mytable
            Table "public.mytable"
  Column  |         Type          | Modifiers
----------+-----------------------+-----------
 mycolumn | character varying(25) |


Note the +4 ... this is a hangover from days gone by, but varchar
typmods are still defined as 4 more than what the user said.

*Practice* on a scratch database to make sure you have it right.
Also I'd suggest doing it inside a BEGIN block so you can roll it
back if you mess up.  Use \d to verify that the table looks as you
expect before committing.

BTW, this trick doesn't really work nicely for anything except the
case of increasing the field width of a varchar column, so that's
why there's not a cleaner interface for it ...

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: PostgreSQL Gotchas
Следующее
От: Tom Lane
Дата:
Сообщение: Re: PostgreSQL Gotchas