Re: \copy and serial type - Mailing list pgsql-novice

From Andrew McMillan
Subject Re: \copy and serial type
Date
Msg-id 1018864516.30516.328.camel@kant.mcmillan.net.nz
Whole thread Raw
In response to \copy and serial type  (Masse Jacques <jacques.masse@bordeaux.cemagref.fr>)
List pgsql-novice
On Mon, 2002-04-15 at 21:42, Masse Jacques wrote:
> I use to enter data in my db with \copy large text files (exports from
> MS-Excel).
>
> Is there a mean to auto update  the primary key (as serial) or do I have to
> calculate it each time with a function ?

Here's one way:

\copy table_without_serial from filename
create sequence myseq;
create table table_with_serial
 as select nextval('myseq'), * from table_without_serial;
drop table_without_serial;

Regards,
                    Andrew.
--
--------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/        PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201    MOB: +64(21)635-694    OFFICE: +64(4)499-2267
       Are you enrolled at http://schoolreunions.co.nz/ yet?


pgsql-novice by date:

Previous
From: Masse Jacques
Date:
Subject: \copy and serial type
Next
From: "Alessandro"
Date:
Subject: About select