From: | Raymond O'Donnell <rod(at)iol(dot)ie> |
---|---|
To: | Robert Buckley <robertdbuckley(at)yahoo(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: create a script which imports csv data |
Date: | 2012-06-28 11:59:56 |
Message-ID: | 4FEC473C.2080403@iol.ie |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 28/06/2012 12:53, Robert Buckley wrote:
> Hi,
>
> I have to create a script which imports csv data into postgresql ...and
> have a few questions about the best way to do it.
>
> The csv data is automatically created from an external database so I
> have no influence over which columns etc are downloaded.
>
> The csv comes without an fid field and has therefore no unique identifier.
>
> How can I best create a table for the import?
>
> Would I first create a table without an fid and then after the import
> create a sequence and add the sequence to the table, then somehow update
> the fid field?
>
> could anyone show me the best way to do this?
Yes, you can do that - create the table initially without a primary key,
import the data, then do something like this:
alter table Anlagenregister_Aktuell_2011 add column fid serial;
update Anlagenregister_Aktuell_2011 set fid =
nextval('Anlagenregister_Aktuell_2011_fid_seq');
As an aside, note that the upper-case letters in the table name get
folded automatically to lower--case unless you double-quote it:
"Anlagenregister_Aktuell_2011".
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie
From | Date | Subject | |
---|---|---|---|
Next Message | Berend Tober | 2012-06-28 12:12:40 | Re: create a script which imports csv data |
Previous Message | Robert Buckley | 2012-06-28 11:53:07 | create a script which imports csv data |