Possible to create nodes and relationships between them at once when loading from CSV?

I have csv file:

customer_no | product_no | purchase_date

I'd like to create nodes "client", nodes "product" and create relationships "bought" between them.
I start with:

LOAD CSV WITH HEADERS FROM 'file:///test.txt' AS row FIELDTERMINATOR '|'
WITH row LIMIT 10
WITH MERGE (c:client {client_no: toInteger(row.customer_no)})
WITH MERGE (p:product {product_number: toInteger(row.product_no)})
CALL apoc.create.relationship(c, "BOUGHT" , {purchase_date: row.purchase_date}, p)

But, sure, this syntax is not correct. Is this possible what I want? If so what is the proper query?
Regards

Try this:

LOAD CSV WITH HEADERS FROM 'file:///test.txt' AS row FIELDTERMINATOR '|'
WITH row LIMIT 10

MERGE (c:client {client_no: toInteger(row.customer_no)})
MERGE (p:product {product_number: toInteger(row.product_no)})

//in .csv all the values will be in string format... use this to covert to date format
WITH apoc.date.format(apoc.date.parse(row.purchase_date, 'ms', 'yyyy-MM-dd'), 'ms', 'yyyy-MM-dd') as purchdte, c, p

MERGE(c)-[:BOUGHT {purchase_date: purchdte}]->(p)

Thank you very much - works!

I have another file with with client's visits.

client_no | visited_page

I'd like to add this information to existing nodes 'client' so I have

page <-[VISITED]-client-[BOUGHT]->product

I start with:
(I want to create new node v and then find right node 'c' to finally build relationship)

LOAD CSV WITH HEADERS FROM 'file:///visits.txt' AS row FIELDTERMINATOR '|'
MERGE (v:Page {page_no: toInteger(row.visited_page)})
WITH MATCH
  (c:Client), (v:Page)
WHERE c.client_no = toInteger(row.client_no) AND v.page_no = toInteger(row.visited_page)
MERGE (c)-[r:VISITED]->(v)

But I got "Variable c not defined" :frowning:

EDIT
I composed such query (and looks like it works) - correct?

LOAD CSV WITH HEADERS FROM 'file:///visits.txt' AS row FIELDTERMINATOR '|'
MATCH
  (c:Client {client_no: toInteger(row.client_no)})
MERGE (v:Page {page_no: toInteger(row.visited_page)})
CREATE (c)-[r:VISITED]->(v)

You cannot use 'WITH' before 'MATCH'. First use 'MATCH' to find a node and if you want propagate the node variable then you should WITH a (a is the node variable like MATCH(a:Customer)).

MATCH
  (c:Client {client_no: toInteger(row.client_no)})
MERGE (v:Page {page_no: toInteger(row.visited_page)})
CREATE (c)-[r:VISITED]->(v)

Here you have to use 'WITH'

MATCH
  (c:Client {client_no: toInteger(row.client_no)})
with c, row

MERGE (v:Page {page_no: toInteger(row.visited_page)})
CREATE (c)-[r:VISITED]->(v)

Thank you very much for your help!