The COPY command supports wild cards!

Moderator: NorbertKrupa

Post Reply
User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

The COPY command supports wild cards!

Post by JimKnicely » Tue May 01, 2012 8:34 pm

The documentation doesn't mention this, but the COPY command supports wild cards...

Example:

Code: Select all

COPY some_table FROM '/path/to/data/ClickStreamData_201?/*' DIRECT... 
When would this be useful? For example, you have many tables storing history including folders for the years 2010, 2011, 2012, etc. Each "year" folder contains tables for each month. You can load in separate streams each year or month and they will load in serial - one after other.

PS. Thanks to vertica-forums user sKwa for this handy tip!
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: The COPY command supports wild cards!

Post by id10t » Tue May 01, 2012 8:59 pm

Example:
[*] Create data for example:

Code: Select all

test_db=> \! mkdir -p /tmp/vertica
test_db=> \! echo -e "one\ntwo\nthree" > /tmp/vertica/data_01.txt
test_db=> \! echo -e "one\ntwo\nthree" > /tmp/vertica/data_02.txt
test_db=> \! echo -e "one\ntwo\nthree" > /tmp/vertica/data_03.txt
test_db=> \! echo -e "one\ntwo\nthree" > /tmp/vertica/data_04.txt
[*]Show data

Code: Select all

test_db=> \! ls /tmp/vertica
data_01.txt  data_02.txt  data_03.txt  data_04.txt
test_db=> \! cat /tmp/vertica/data_01.txt
one
two
three
[*]Copy data:

Code: Select all

test_db=> create table tbl (var varchar(5));
CREATE TABLE
test_db=> copy tbl from '/tmp/vertica/data_0?.txt';
 Rows Loaded 
-------------
          12
(1 row)

test_db=> copy tbl from '/tmp/vertica/data*';
 Rows Loaded 
-------------
          12
(1 row)

DataWhisperer
Newbie
Newbie
Posts: 16
Joined: Fri May 11, 2012 12:25 pm

Re: The COPY command supports wild cards!

Post by DataWhisperer » Sat May 12, 2012 8:51 am

Note: the WILDCARD (*) will only allow up to 50 files in a single directory to prevent overloading. It doesn't say this in the documentation, but when you try to COPY several thousand files with a wildcard, it complains. ;-)

Though, it is possible to loop through a directory (even recursively) with a bash script and use vsql to and a parameterized query and to load the files. :geek:

ssrao
Newbie
Newbie
Posts: 14
Joined: Fri Jun 07, 2013 2:37 pm

Re: The COPY command supports wild cards!

Post by ssrao » Thu Jun 20, 2013 11:39 am

My directory containing more than 1000files.

which command I need to write in copy command

copy mdn.customer from '/home/dbadmin/customer/cust_?' delimiter '|' direct abort on error;

copy mdn.customer from '/home/dbadmin/customer/*.log' delimiter '|' direct abort on error;

Above commands are not working,what command I need to write to load all logs at one time.

Thanks in advance

Post Reply

Return to “Vertica Data Load”