Import PostgreSQL .sql into Neo4j

4

I have a PostgreSQL backup .sql file and I want to import this file into Neo4j (database in graph). How do I?

    
asked by anonymous 14.03.2016 / 14:34

2 answers

2

@BrunoRB is correct, you will need at some point to create a Modelo Relacional <--> Grafo mapping function of your data. This tutorial from Neo4j can help you .

By simplifying the above link, you will turn every record of every table in your database into a node in the Neo4j graph.

Given the following table:

                                Table "public.consumidor"
 Column |         Type          |                        Modifiers
--------+-----------------------+---------------------------------------------------------
 id     | integer               | not null default nextval('consumidor_id_seq'::regclass)
 nome   | character varying(40) |

What you need to do is export it to a .csv file using the COPY command from PostgreSQL:

COPY (SELECT * FROM consumidor) TO '/tmp/comsumidor.csv' WITH CSV header;

And create the equivalent nodes in Neo4j using the LOAD CSV command of the Cypher language:

// Create customers
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:consumidor.csv" AS row
CREATE (:Consumidor {nome: row.nome, consumidorId: row.id});
    
14.03.2016 / 20:59
1

There is no easy way. You will have to import this SQL into postgresql, create its equivalent structure in NEO4J and then write a data mapping code that will extract them from postgres and play in the equivalent NEO4J fields.

    
14.03.2016 / 14:38