Search Postgresql Archives

Re: Long running update

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

 



"Andrew Janian" <ajanian@xxxxxxxxxxxxx> 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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

[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