![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a CSV file with 400,000 lines of email mailing list information that I need to migrate to a new PostgreSQL database. Each line has all the info I need except a PK (I usually use an int4 column for a PK). |
#3
| |||
| |||
|
|
From: Peter Eisentraut <peter_e (AT) gmx (DOT) net Date: Sat, 6 Nov 2004 21:21:25 +0100 To: Hunter Hillegas <lists (AT) lastonepicked (DOT) com>, PostgreSQL pgsql-general (AT) postgresql (DOT) org Subject: Re: [GENERAL] Mass Import/Generate PKs Hunter Hillegas wrote: I have a CSV file with 400,000 lines of email mailing list information that I need to migrate to a new PostgreSQL database. Each line has all the info I need except a PK (I usually use an int4 column for a PK). You could import the file into PostgreSQL and add a primary key column later. -- Peter Eisentraut http://developer.postgresql.org/~petere/ |
#4
| |||
| |||
|
|
That sounds nice and easy... So, I would do something like 'ALTER TABLE' to generate the PK column? What would be the best way to populate it? Is there an area of doco I should be looking at? Thanks, Hunter From: Peter Eisentraut <peter_e (AT) gmx (DOT) net Date: Sat, 6 Nov 2004 21:21:25 +0100 To: Hunter Hillegas <lists (AT) lastonepicked (DOT) com>, PostgreSQL pgsql-general (AT) postgresql (DOT) org Subject: Re: [GENERAL] Mass Import/Generate PKs Hunter Hillegas wrote: I have a CSV file with 400,000 lines of email mailing list information that I need to migrate to a new PostgreSQL database. Each line has all the info I need except a PK (I usually use an int4 column for a PK). You could import the file into PostgreSQL and add a primary key column later. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html |
#5
| |||
| |||
|
|
the simplest way to do it seems to be adding a SERIAL column to your table, and then adding a primary key constraint: 1)insert data into table 2)ALTER TABLE <table> ADD id SERIAL; 3)ALTER TABLE <table> ADD CONSTRAINT <table>_pk PRIMARY KEY (id); |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
-----Original Message----- From: pgsql-general-owner (AT) postgresql (DOT) org [mailto gsql-general-owner (AT) postgresql (DOT) org] On Behalf OfHunter Hillegas Sent: Saturday, November 06, 2004 3:01 PM To: PostgreSQL Subject: [GENERAL] Mass Import/Generate PKs I have a CSV file with 400,000 lines of email mailing list information that I need to migrate to a new PostgreSQL database. Each line has all the info I need except a PK (I usually use an int4 column for a PK). If the file were smaller I would probably just use Excel to pop in a PK and then just load into the table... Since Excel chokes on files greater than 65k lines, this won't work. Is there a way to get this done inside psql for instance? Or another route? Thanks, Hunter ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org) |
![]() |
| Thread Tools | |
| Display Modes | |
| |