Search Postgresql Archives

Re: Smaller data types use same disk space

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

 



> > Has there been any discussion of providing the ability to re-order
> > table columns through an ALTER TABLE command?  I would love to see
> > this; when I add in a new column, I often want to put it next to
> > something just to be more visually appealing when I'm running ad-hoc
> > queries.  It could potentially address this problem as well.
> 
> see: http://wiki.postgresql.org/wiki/Alter_column_position
> as well as extensive discussion in the archives.
> 
> merlin


Hello,

actually columns position can be changed with alter table using
ALTER TYPE ... USING. All constraints, indexes and possible serials 
naturally still need to be handled as well

However, I'm not sure that this alternative may have any advantage 
upon the method described on the wiki page.

  create temp table test (a serial, b varchar); 
  insert into test (b) values ('a'),('b');

  create index a_i on test(a);
  create index b_i on test(b);
  create index ab_i on test(a,b);

  alter table test
    ALTER a TYPE varchar USING b,
    ALTER b TYPE int     USING a;
  
  alter table test  rename b to _b;
  alter table test  rename a to b;
  alter table test  rename _b to a;

  select * from test;

  \d+ test

Marc Mamin




-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[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