Re: create a script which imports csv data

Поиск
Список
Период
Сортировка
От Raymond O'Donnell
Тема Re: create a script which imports csv data
Дата
Msg-id 4FEC473C.2080403@iol.ie
обсуждение исходный текст
Ответ на create a script which imports csv data  (Robert Buckley <robertdbuckley@yahoo.com>)
Список 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@iol.ie



В списке pgsql-general по дате отправления:

Предыдущее
От: Robert Buckley
Дата:
Сообщение: create a script which imports csv data
Следующее
От: "Marc Mamin"
Дата:
Сообщение: Re: create a script which imports csv data