[plug] OT-ish: Postgres table (ab)usage

Ryan ryan at slowest.net
Fri Feb 22 16:24:55 WST 2002


Boo!

Does anyone know if there is a way to preserve sequences in PostgreSQL
when removing a column for a table .... in a more efficient manner than
shown below? 

I am doing this in order to delete a column from a table.  Rather than
bore you all with the real data, I'll bore you even more with a
hypothetical:

I'll make a table:

> create table member (id SERIAL, name BYTEA, hobby BYTEA);
> insert into member (name, hobby) values ('ryan','lamer');

Which now looks like this:

                             Table "member"
 Attribute |  Type   |                     Modifier

-----------+---------+--------------------------------------------------
-
 id        | integer | not null default nextval('"member_id_seq"'::text)
 name      | bytea   | 
 hobby     | bytea   | 
Index: member_id_key

If I want to delete the hobby column I go about it as such:

> create table temp as select id, name from member;
> drop table member;
> create table member as select * from temp;
> drop table temp;

This drops the sequence modifier from the 'id' field, so I then do:

> alter table member alter id set default
nextval('"member_id_seq"'::text);

Is there a better way to do this?  Maybe a way to select the modifier
into the temp table in the first place?

Thanks.

Ryan




More information about the plug mailing list