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

Leon Blackwell leon at lostrealm.com
Fri Feb 22 17:25:51 WST 2002


On Fri, Feb 22, 2002 at 04:24:55PM +0800, Ryan wrote:
> Boo!

Argh... you scared me...


> Is there a better way to do this?

Design your tables properly in the first place?  :)


I'm not sure if this is any better, but it might solve whatever you're
trying to do:

-- Use create temporary here and PostgreSQL will automagically clean
--  it up when the current session ends
create temporary table temp as select id, name from member;

-- Create the table, specifying the (existing) sequence should be used
-- We can't use AS here, since we're specifying the columns
--  (not, I don't know why... PostgreSQL just doesn't like it)
create table member (
    id integer not null default nextval('"member_id_seq"'::text),
    name BYTEA
    );

-- Grab all the values
-- If we do this as a second step, everything works nicely
insert into member select * from temp;

-- This isn't required for temporary tables, but I'm anal  :)
drop table temp;


-- 
 Leon Blackwell                | Never be afraid to try something new. 
 http://www.lostrealm.com/     | Remember, amateurs built the ark. 
 jabber:Lionfire at lostrealm.com | Professionals built the Titanic.



More information about the plug mailing list