Sam Muller
Sam Muller

Reputation: 73

Connect Neo4J on an existing Postgresql database

I'm a Neo4j new user and I played around with the webadmin interface of Neo4j to create small databases and simple queries in Cypher. Now I want to use Neo4J to create a graph with my existing database. It's a postgresql database with millions of entries with the same structure (Neo4J is very adapted to represent these data). My question is how to import these data ? What is the easiest way to do that ? I already saw that Cypher recognizes csv files but do I have to create a csv file with my data or is there another way to import them ? Thank you for your help. Sam

Upvotes: 3

Views: 2066

Answers (2)

Lierre
Lierre

Reputation: 11

Seconding the JDBC approach, there is a great documentation about using JDBC to connect with RDBMS. Summary of the steps plus extra steps not mentioned in docs:

  1. Check latest version of neo4j APOC extended plugin here and download
  2. Create a new project using neo4j version compatible with step 1
  3. Install APOC plugin in the project following this step
  4. Install java if not already installed
  5. Download vendor and java versions compatible JDBC .jar file from link in docs table
  6. Find $NEO4J_HOME
  7. Copy 1 and 5 to $NEO4J_HOME\plugins\, check that $NEO4J_HOME\plugins\ contains APOC core and extended, and DBMS specific .jar files
  8. Restart project
  9. Open project and load driver with Cypher CALL apoc.load.driver('{JDBC driver class name for the vendor}'), this is a non exhaustive list of the names
  10. Run Cypher CALL apoc.load.jdbc('jdbc:{connection string}','select * from {table name}') YIELD row to test connection

Upvotes: 0

Stefan Armbruster
Stefan Armbruster

Reputation: 39915

One option is to export your postgres data to csv and apply LOAD CSV to import them into the graph.

Another way is writing a script in a language of choice (I'd vote for groovy here) that connects to Postgres using JDBC and connects to Neo4j and then applies the business logic to transform between the two.

A third option is using a ETL tool like Talend. It basically does the same as your custom script but provides a point & click interface to define the transformation, see http://neo4j.com/blog/fun-with-music-neo4j-and-talend/ for more details.

Upvotes: 1

Related Questions