Skip site navigation (1) Skip section navigation (2)

Re: Inserting a new column in between.

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Inserting a new column in between.
Date: 2007-02-25 09:03:09
Message-ID: 20070225090308.GA6635@KanotixBox (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novice
RPK <rohitprakash123(at)indiatimes(dot)com> schrieb:

> 
> Andreas,
> 
> I am talking about inserting a field or changing their order in the
> structure itself. In MS Access and SQL Server we have this facility. Some
> times I need to shift the less important field to the last so that when I
> query using:
> 
> Select * from tablename;

You should don't do that! Why? For instance, you have a table with many
rows, including BLOBs. Your applivation needs only a few columns, but
you select * returns the whole rows.


So, but no problem:

test=# create table foo (a int, c int);
CREATE TABLE
test=*# insert into foo values (1,3);
INSERT 0 1
test=*# commit;
COMMIT


Okay, we have a table with columns a and c, and now i notice i forgot
the column b. No problem:

test=# begin;
BEGIN
test=*# create table foo_temp as select a, null::int as b, c from foo;
SELECT
test=*# drop table foo;
DROP TABLE
test=*# alter table foo_temp rename to foo;
ALTER TABLE
test=*# commit;
COMMIT
test=# select * from foo;
 a | b | c
---+---+---
 1 |   | 3
(1 row)



Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

In response to

pgsql-novice by date

Next:From: joseph speigleDate: 2007-02-26 01:45:59
Subject: trigger not firing
Previous:From: Noel FauxDate: 2007-02-25 09:00:50
Subject: Re: Inserting a new column in between.

pgsql-general by date

Next:From: Greg Sabino MullaneDate: 2007-02-25 14:30:53
Subject: Re: Wikipedia on Postgres (was Re: postgresql vs mysql)
Previous:From: Noel FauxDate: 2007-02-25 09:00:50
Subject: Re: Inserting a new column in between.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group