Skip to content
Blog

Export CSV

The COPY TO clause can export query results to a CSV file, and is used as follows:

COPY (MATCH (u:User) RETURN u.*) TO 'user.csv' (header=true);

The CSV file consists of the following fields:

u.name,u.age
Adam,30
Karissa,40
Zhang,50
Noura,25

Nested data types like lists and structs will be represented as strings within their respective columns.

Available options are:

OptionDefault ValueDescription
ESCAPE\Character used to escape special characters in CSV
DELIM,Character that separates fields in the CSV
QUOTE"Character used to enclose fields containing special characters or spaces
HeaderfalseIndicates whether to output a header row

Another example is shown below.

COPY (MATCH (a:User)-[f:Follows]->(b:User) RETURN a.name, f.since, b.name) TO 'follows.csv' (header=false, delim='|');

This outputs the following results to follows.csv:

Adam|2020|Karissa
Adam|2020|Zhang
Karissa|2021|Zhang
Zhang|2022|Noura