Skip to main content

Copy from CSV sfile

  • November 23, 2016
  • 1 reply
  • 10 views

Lim

Hi,

 

Do I have to create a table before I can use copy statement to import a CSV file to that table?

Can I import CSV file at the same time a new table is created?

Thank you.

1 reply

Adrian_Oprea_1
Forum|alt.badge.img+1
  • Participating Frequently
  • November 24, 2016

 You can grab the headers of the file and create the table before you run copy cmd. (oldschool)

Or 

 

You can use External table build definition on copy cmd:

 

CREATE EXTERNAL TABLE ext1 (x integer) AS COPY FROM '/tmp/ext1.dat' DELIMITER ',';

 

Note : there is need for access on a location for the user who will run the copy command.

See more details here 

 

https://my.vertica.com/docs/8.0.x/HTML/index.htm#Authoring/SQLReferenceManual/Statements/CREATEEXTERNALTABLEASCOPY.htm

 

Both are not as fast/ optimium as the default copy cmd on a existing table.