Thread: \copy and serial type

\copy and serial type

From
Masse Jacques
Date:
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 ?

Regards

___________________________________________
Jacques Massé
Tel. 33 (0)5 57 89 08 11 - Fax 33 (0)5 57 89 08 01



Re: \copy and serial type

From
Andrew McMillan
Date:
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?