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.ageAdam,30Karissa,40Zhang,50Noura,25
Nested data types like lists and structs will be represented as strings within their respective columns.
Available options are:
Option | Default Value | Description |
---|---|---|
ESCAPE | \ | Character used to escape special characters in CSV |
DELIM or DELIMITER | , | Character that separates fields in the CSV |
QUOTE | " | Character used to enclose fields containing special characters or spaces |
Header | false | Indicates 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|KarissaAdam|2020|ZhangKarissa|2021|ZhangZhang|2022|Noura