Search Postgresql Archives

Re: Inserting a new column in between.

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

 



RPK <rohitprakash123@xxxxxxxxxxxxxx> 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°


[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