The COPY command supports wild cards!

Forum to discuss topics related to loading data into Vertica (i.e. COPY command)

The COPY command supports wild cards!

Postby knicely87 » 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
HP ATP - Vertica Big Data Solutions V1 Certified
User avatar
knicely87
Site Admin
Site Admin
 
Posts: 765
Joined: Sat Jan 21, 2012 4:58 am

Message from our Sponsor

Sponsor

Sponsor
 

Re: The COPY command supports wild cards!

Postby sKwa » 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)
I'm not a computer expert - if you take anything I write as a suggestion then: DO NOT come to me crying it is my fault that YOU ruined your system!
sKwa
Master
Master
 
Posts: 367
Joined: Mon Apr 16, 2012 2:44 pm

Re: The COPY command supports wild cards!

Postby 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:
DataWhisperer
Newbie
Newbie
 
Posts: 18
Joined: Fri May 11, 2012 12:25 pm


Return to Vertica Data Load

Who is online

Users browsing this forum: No registered users and 1 guest