Search Postgresql Archives

Re: create a script which imports csv data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux