How to return all the properties in Neo4j to be in diffrent columns












0














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









share|improve this question





























    0














    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









    share|improve this question



























      0












      0








      0







      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









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 14:51









      Chris Skardon

      4,97322338




      4,97322338










      asked Nov 21 '18 at 16:52









      nananana

      144




      144
























          2 Answers
          2






          active

          oldest

          votes


















          0














          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:



          enter image description here






          share|improve this answer





























            0














            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





            share|improve this answer





















            • 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










            • 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











            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            0














            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:



            enter image description here






            share|improve this answer


























              0














              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:



              enter image description here






              share|improve this answer
























                0












                0








                0






                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:



                enter image description here






                share|improve this answer












                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:



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 17:03









                BajalBajal

                2,22411118




                2,22411118

























                    0














                    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





                    share|improve this answer





















                    • 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










                    • 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
















                    0














                    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





                    share|improve this answer





















                    • 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










                    • 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














                    0












                    0








                    0






                    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





                    share|improve this answer












                    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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    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 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










                    • @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










                    • @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










                    • @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


















                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    To store a contact into the json file from server.js file using a class in NodeJS

                    Redirect URL with Chrome Remote Debugging Android Devices

                    Dieringhausen