Thread: Using seq. objects with COPY FROM?

Using seq. objects with COPY FROM?

From
"Shivin M"
Date:
Hello,
I was wondering whether you can make use of sequence objects along with COPY FROM command?

This is my scenario:

I have table: name_list(id SERIAL PRIMARY KEY, name varchar(10))

So, there exists a sequence object: "name_list_id_seq" that starts from 1.

I have a CSV file that has names of people.
eg:

name

tom
mary
harry

Now, I want to read this file into the table 'name_table', and at the same time, add sequence object's ("name_list_id_seq") next value to each row.
So, the contents of "name_table" now look like:

name_table
 
id  name
---  -------
1   tom
2   mary
3   harry

Can anyone tell me how this can be done?
Thank you.

Re: Using seq. objects with COPY FROM?

From
"A. Kretschmer"
Date:
am  Mon, dem 20.11.2006, um  9:00:01 -0500 mailte Shivin M folgendes:
> Hello,
> I was wondering whether you can make use of sequence objects along with COPY
> FROM command?
>
> Can anyone tell me how this can be done?

copy name_table(name) from 'file.csv';


Hint: specify the columns...


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47215,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net