How to return all the properties in Neo4j to be in diffrent columns
I know, we can export neo4j database to CSV file by clicking a ready button.
After we implement this cypher query:
Match (n)
return n
But this query gives us all the properties as 1 rows.
My question is: which Cypher query to implement, before exporting to CSV file to give us all the properties as in separate columns, even if the nodes do not have the same properties,
For example:
node(0) has: name, age.
node(1) has: name, age.
node(2) has: name, address.
node(3) has: name, phone No.
node(4) has: name, age.
node(5) has: name, DoB.
I need the result to be as:
name age address phone No DoB
Tom 22
Smith 18
Lee 123abc
Perry 01234
Sara 40
Tom 11/11/2000
Not as:
n
Tom, 22
Smith, 18
Lee, 123abc
Perry, 01234
Sara, 40
Tom, 11/11/2000
neo4j cypher spring-data-neo4j neo4j-apoc
add a comment |
I know, we can export neo4j database to CSV file by clicking a ready button.
After we implement this cypher query:
Match (n)
return n
But this query gives us all the properties as 1 rows.
My question is: which Cypher query to implement, before exporting to CSV file to give us all the properties as in separate columns, even if the nodes do not have the same properties,
For example:
node(0) has: name, age.
node(1) has: name, age.
node(2) has: name, address.
node(3) has: name, phone No.
node(4) has: name, age.
node(5) has: name, DoB.
I need the result to be as:
name age address phone No DoB
Tom 22
Smith 18
Lee 123abc
Perry 01234
Sara 40
Tom 11/11/2000
Not as:
n
Tom, 22
Smith, 18
Lee, 123abc
Perry, 01234
Sara, 40
Tom, 11/11/2000
neo4j cypher spring-data-neo4j neo4j-apoc
add a comment |
I know, we can export neo4j database to CSV file by clicking a ready button.
After we implement this cypher query:
Match (n)
return n
But this query gives us all the properties as 1 rows.
My question is: which Cypher query to implement, before exporting to CSV file to give us all the properties as in separate columns, even if the nodes do not have the same properties,
For example:
node(0) has: name, age.
node(1) has: name, age.
node(2) has: name, address.
node(3) has: name, phone No.
node(4) has: name, age.
node(5) has: name, DoB.
I need the result to be as:
name age address phone No DoB
Tom 22
Smith 18
Lee 123abc
Perry 01234
Sara 40
Tom 11/11/2000
Not as:
n
Tom, 22
Smith, 18
Lee, 123abc
Perry, 01234
Sara, 40
Tom, 11/11/2000
neo4j cypher spring-data-neo4j neo4j-apoc
I know, we can export neo4j database to CSV file by clicking a ready button.
After we implement this cypher query:
Match (n)
return n
But this query gives us all the properties as 1 rows.
My question is: which Cypher query to implement, before exporting to CSV file to give us all the properties as in separate columns, even if the nodes do not have the same properties,
For example:
node(0) has: name, age.
node(1) has: name, age.
node(2) has: name, address.
node(3) has: name, phone No.
node(4) has: name, age.
node(5) has: name, DoB.
I need the result to be as:
name age address phone No DoB
Tom 22
Smith 18
Lee 123abc
Perry 01234
Sara 40
Tom 11/11/2000
Not as:
n
Tom, 22
Smith, 18
Lee, 123abc
Perry, 01234
Sara, 40
Tom, 11/11/2000
neo4j cypher spring-data-neo4j neo4j-apoc
neo4j cypher spring-data-neo4j neo4j-apoc
edited Nov 27 '18 at 14:51
Chris Skardon
4,97322338
4,97322338
asked Nov 21 '18 at 16:52
nananana
144
144
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
One way is to use apoc
to export it as CSV.
CALL apoc.export.csv.query("MATCH (n) return n", "/tmp/results.csv", {})
Sample result looks like this, which you can transform to a structure you like using other tools like jq
:
add a comment |
To truly get the format you want, you need to explicitly state every column in your Cypher
MATCH (n) RETURN n.name as name, n.age as age, n.address as address, n.'phone No' as 'phone no', n.DoB as DoB
A simpler alternative would be to export the properties as a map, and then just set them when loading. Without apoc though, setting the labels again also needs to be explicit.
MATCH (n) RETURN PROPERTIES(n) as props, LABELS(n) as labels
-----
LOAD CSV ... as csv
// without apoc
CREATE(n)
SET n=csv.props
// or with apoc
CALL apoc.create.node(csv.labels, csv.props) YIELD node
Yes this solution ideal when you have a small dataset and you know in advanced what properties that you have, but in case of a large dataset how we get all properties without losing any,,
– nana
Nov 22 '18 at 7:37
@nana In Cypher, you have to explicitly name every column you are returning. Depending on why you need the csv in this format, It would probably be easier toRETURN PROPERTIES(n)
and than re-parse the output csv to the format you want with a short java/python script.
– Tezra
Nov 22 '18 at 8:00
In [LOAD CSV ... as csv] do we need to write the path that we want to store the csv file in, if so how because I tried many format gave me errors
– nana
Nov 22 '18 at 9:56
@nana That is a seprate cypher, that assumes you are exporting to import to a new db. neo4j.com/docs/developer-manual/current/cypher/clauses/load-csv If you aren't importing, ignore what is below the ---
– Tezra
Nov 22 '18 at 16:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416974%2fhow-to-return-all-the-properties-in-neo4j-to-be-in-diffrent-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
One way is to use apoc
to export it as CSV.
CALL apoc.export.csv.query("MATCH (n) return n", "/tmp/results.csv", {})
Sample result looks like this, which you can transform to a structure you like using other tools like jq
:
add a comment |
One way is to use apoc
to export it as CSV.
CALL apoc.export.csv.query("MATCH (n) return n", "/tmp/results.csv", {})
Sample result looks like this, which you can transform to a structure you like using other tools like jq
:
add a comment |
One way is to use apoc
to export it as CSV.
CALL apoc.export.csv.query("MATCH (n) return n", "/tmp/results.csv", {})
Sample result looks like this, which you can transform to a structure you like using other tools like jq
:
One way is to use apoc
to export it as CSV.
CALL apoc.export.csv.query("MATCH (n) return n", "/tmp/results.csv", {})
Sample result looks like this, which you can transform to a structure you like using other tools like jq
:
answered Nov 21 '18 at 17:03
BajalBajal
2,22411118
2,22411118
add a comment |
add a comment |
To truly get the format you want, you need to explicitly state every column in your Cypher
MATCH (n) RETURN n.name as name, n.age as age, n.address as address, n.'phone No' as 'phone no', n.DoB as DoB
A simpler alternative would be to export the properties as a map, and then just set them when loading. Without apoc though, setting the labels again also needs to be explicit.
MATCH (n) RETURN PROPERTIES(n) as props, LABELS(n) as labels
-----
LOAD CSV ... as csv
// without apoc
CREATE(n)
SET n=csv.props
// or with apoc
CALL apoc.create.node(csv.labels, csv.props) YIELD node
Yes this solution ideal when you have a small dataset and you know in advanced what properties that you have, but in case of a large dataset how we get all properties without losing any,,
– nana
Nov 22 '18 at 7:37
@nana In Cypher, you have to explicitly name every column you are returning. Depending on why you need the csv in this format, It would probably be easier toRETURN PROPERTIES(n)
and than re-parse the output csv to the format you want with a short java/python script.
– Tezra
Nov 22 '18 at 8:00
In [LOAD CSV ... as csv] do we need to write the path that we want to store the csv file in, if so how because I tried many format gave me errors
– nana
Nov 22 '18 at 9:56
@nana That is a seprate cypher, that assumes you are exporting to import to a new db. neo4j.com/docs/developer-manual/current/cypher/clauses/load-csv If you aren't importing, ignore what is below the ---
– Tezra
Nov 22 '18 at 16:52
add a comment |
To truly get the format you want, you need to explicitly state every column in your Cypher
MATCH (n) RETURN n.name as name, n.age as age, n.address as address, n.'phone No' as 'phone no', n.DoB as DoB
A simpler alternative would be to export the properties as a map, and then just set them when loading. Without apoc though, setting the labels again also needs to be explicit.
MATCH (n) RETURN PROPERTIES(n) as props, LABELS(n) as labels
-----
LOAD CSV ... as csv
// without apoc
CREATE(n)
SET n=csv.props
// or with apoc
CALL apoc.create.node(csv.labels, csv.props) YIELD node
Yes this solution ideal when you have a small dataset and you know in advanced what properties that you have, but in case of a large dataset how we get all properties without losing any,,
– nana
Nov 22 '18 at 7:37
@nana In Cypher, you have to explicitly name every column you are returning. Depending on why you need the csv in this format, It would probably be easier toRETURN PROPERTIES(n)
and than re-parse the output csv to the format you want with a short java/python script.
– Tezra
Nov 22 '18 at 8:00
In [LOAD CSV ... as csv] do we need to write the path that we want to store the csv file in, if so how because I tried many format gave me errors
– nana
Nov 22 '18 at 9:56
@nana That is a seprate cypher, that assumes you are exporting to import to a new db. neo4j.com/docs/developer-manual/current/cypher/clauses/load-csv If you aren't importing, ignore what is below the ---
– Tezra
Nov 22 '18 at 16:52
add a comment |
To truly get the format you want, you need to explicitly state every column in your Cypher
MATCH (n) RETURN n.name as name, n.age as age, n.address as address, n.'phone No' as 'phone no', n.DoB as DoB
A simpler alternative would be to export the properties as a map, and then just set them when loading. Without apoc though, setting the labels again also needs to be explicit.
MATCH (n) RETURN PROPERTIES(n) as props, LABELS(n) as labels
-----
LOAD CSV ... as csv
// without apoc
CREATE(n)
SET n=csv.props
// or with apoc
CALL apoc.create.node(csv.labels, csv.props) YIELD node
To truly get the format you want, you need to explicitly state every column in your Cypher
MATCH (n) RETURN n.name as name, n.age as age, n.address as address, n.'phone No' as 'phone no', n.DoB as DoB
A simpler alternative would be to export the properties as a map, and then just set them when loading. Without apoc though, setting the labels again also needs to be explicit.
MATCH (n) RETURN PROPERTIES(n) as props, LABELS(n) as labels
-----
LOAD CSV ... as csv
// without apoc
CREATE(n)
SET n=csv.props
// or with apoc
CALL apoc.create.node(csv.labels, csv.props) YIELD node
answered Nov 21 '18 at 19:27
TezraTezra
5,03621042
5,03621042
Yes this solution ideal when you have a small dataset and you know in advanced what properties that you have, but in case of a large dataset how we get all properties without losing any,,
– nana
Nov 22 '18 at 7:37
@nana In Cypher, you have to explicitly name every column you are returning. Depending on why you need the csv in this format, It would probably be easier toRETURN PROPERTIES(n)
and than re-parse the output csv to the format you want with a short java/python script.
– Tezra
Nov 22 '18 at 8:00
In [LOAD CSV ... as csv] do we need to write the path that we want to store the csv file in, if so how because I tried many format gave me errors
– nana
Nov 22 '18 at 9:56
@nana That is a seprate cypher, that assumes you are exporting to import to a new db. neo4j.com/docs/developer-manual/current/cypher/clauses/load-csv If you aren't importing, ignore what is below the ---
– Tezra
Nov 22 '18 at 16:52
add a comment |
Yes this solution ideal when you have a small dataset and you know in advanced what properties that you have, but in case of a large dataset how we get all properties without losing any,,
– nana
Nov 22 '18 at 7:37
@nana In Cypher, you have to explicitly name every column you are returning. Depending on why you need the csv in this format, It would probably be easier toRETURN PROPERTIES(n)
and than re-parse the output csv to the format you want with a short java/python script.
– Tezra
Nov 22 '18 at 8:00
In [LOAD CSV ... as csv] do we need to write the path that we want to store the csv file in, if so how because I tried many format gave me errors
– nana
Nov 22 '18 at 9:56
@nana That is a seprate cypher, that assumes you are exporting to import to a new db. neo4j.com/docs/developer-manual/current/cypher/clauses/load-csv If you aren't importing, ignore what is below the ---
– Tezra
Nov 22 '18 at 16:52
Yes this solution ideal when you have a small dataset and you know in advanced what properties that you have, but in case of a large dataset how we get all properties without losing any,,
– nana
Nov 22 '18 at 7:37
Yes this solution ideal when you have a small dataset and you know in advanced what properties that you have, but in case of a large dataset how we get all properties without losing any,,
– nana
Nov 22 '18 at 7:37
@nana In Cypher, you have to explicitly name every column you are returning. Depending on why you need the csv in this format, It would probably be easier to
RETURN PROPERTIES(n)
and than re-parse the output csv to the format you want with a short java/python script.– Tezra
Nov 22 '18 at 8:00
@nana In Cypher, you have to explicitly name every column you are returning. Depending on why you need the csv in this format, It would probably be easier to
RETURN PROPERTIES(n)
and than re-parse the output csv to the format you want with a short java/python script.– Tezra
Nov 22 '18 at 8:00
In [LOAD CSV ... as csv] do we need to write the path that we want to store the csv file in, if so how because I tried many format gave me errors
– nana
Nov 22 '18 at 9:56
In [LOAD CSV ... as csv] do we need to write the path that we want to store the csv file in, if so how because I tried many format gave me errors
– nana
Nov 22 '18 at 9:56
@nana That is a seprate cypher, that assumes you are exporting to import to a new db. neo4j.com/docs/developer-manual/current/cypher/clauses/load-csv If you aren't importing, ignore what is below the ---
– Tezra
Nov 22 '18 at 16:52
@nana That is a seprate cypher, that assumes you are exporting to import to a new db. neo4j.com/docs/developer-manual/current/cypher/clauses/load-csv If you aren't importing, ignore what is below the ---
– Tezra
Nov 22 '18 at 16:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416974%2fhow-to-return-all-the-properties-in-neo4j-to-be-in-diffrent-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown