Import . sql from Postgresql in Neo4j

Asked

Viewed 300 times

4

I have a Postgresql . sql backup file and want to import that file to Neo4j (graph database). How do I?

2 answers

2

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

Simplifying the link above, you will turn each record of each 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 file .csv using the command COPY postgresql:

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

And create equivalent nodes in Neo4j using the command LOAD CSV 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});

1

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.