Re: Smaller data types use same disk space

From: "Marc Mamin" <M(dot)Mamin(at)intershop(dot)de>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>, "Mike Christensen" <mike(at)kitchenpc(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "McGehee, Robert" <Robert(dot)McGehee(at)geodecapital(dot)com>, "Adrian Klaver" <adrian(dot)klaver(at)gmail(dot)com>, "Steve Crawford" <scrawford(at)pinpointresearch(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Smaller data types use same disk space
Date: 2012-07-26 08:27:04
Message-ID: C4DAC901169B624F933534A26ED7DF310861B63C@JENMAIL01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> > 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Johann Spies 2012-07-26 08:55:00 Re: Full text search ts_heading strange result
Previous Message Craig Ringer 2012-07-26 08:19:02 Re: Full text search ts_heading strange result