Exporting Data

COPY TO

COPY ( <SELECT statement> ) TO '<file path>' [WITH (<property> = value, ...)];

<file path> must be a path on the server. This command exports the results of any SELECT statement to the file. There is a special mode when <file path> is empty. In that case, the server automatically generates a file in <HEAVY.AI Directory>/export that is the client session id with the suffix .txt.

Available properties in the optional WITH clause are described in the following table.

When using the COPY TO command, you might encounter the following error:

Query couldn’t keep the entire working set of columns in GPU Memory.

To avoid this error, use the heavysql command \cpu to put your HEAVY.AI server in CPU mode before using the COPY TO command. See Configuration.

Example

COPY (SELECT * FROM tweets) TO '/tmp/tweets.csv';
COPY (SELECT * tweets ORDER BY tweet_time LIMIT 10000) TO
  '/tmp/tweets.tsv' WITH (delimiter = '\t', quoted = 'true', header = 'false');