在'mysql' => [
'driver' => 'mysql',
'host' => $host,
'database' => $database,
'username' => $username,
'password' => $password,
// 'host' => env('DB_HOST', 'localhost'),
// 'database' => env('DB_DATABASE', 'forge'),
// 'username' => env('DB_USERNAME', 'forge'),
// 'password' => env('DB_PASSWORD', ''),
// 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
期间,我将字段转换为带LOAD CSV
的整数,虽然我没有收到任何错误(以及数据加载),但该属性仍被视为字符串。
下面是我运行以填充数据库的代码。我有一个小玩具数据集,您可以在下面参考。
toInt
但是当我在另一个查询中引用该属性时
// Import the HS Cluster nodes
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "https://docs.google.com/spreadsheets/d/11f7-aEN-OURzzPY97Cm8vWZN1lNqYpSmCocNkzAoQe8/pub?gid=0&single=true&output=csv" as row
WITH row
MERGE (s:Student {sid:row.id});
// Import the contacts
// THIS IS THE QUERY THAT I AM USING toINT
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "https://docs.google.com/spreadsheets/d/11f7-aEN-OURzzPY97Cm8vWZN1lNqYpSmCocNkzAoQe8/pub?gid=0&single=true&output=csv" as row
WITH row
MERGE (c:Contact {cid:row.cid, seqnum: toInt(row.seqnum)} );
// Connect the next contacts together
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "https://docs.google.com/spreadsheets/d/11f7-aEN-OURzzPY97Cm8vWZN1lNqYpSmCocNkzAoQe8/pub?gid=0&single=true&output=csv" as row
WITH row
WHERE row.nextcid <> 'NA'
MERGE (c:Contact {cid:row.cid})
MERGE (n:Contact {cid:row.nextcid})
MERGE (c)-[:NEXT]->(n);
但这会产生// I expected this to work
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "https://docs.google.com/spreadsheets/d/11f7-aEN-OURzzPY97Cm8vWZN1lNqYpSmCocNkzAoQe8/pub?gid=0&single=true&output=csv" as row
WITH row
WHERE row.seqnum = 1
MERGE (c:Contact {cid:row.cid})
MERGE (s:Student {sid:row.id})
MERGE (s)-[:HAS_CONTACT]->(c);
但是,当我将(no changes, no rows)
作为字符串引用时,它会按预期工作
seqnum
我错过了什么?
供参考,我正在运行neo4j 2.3.1的社区版,我在OSX 10.9.5上。
非常感谢任何帮助。
答案 0 :(得分:3)
在“预期工作”部分中,您可以过滤CSV文件中的属性,而不是在节点上:
WHERE row.seqnum = 1 // this is still a string from your CSV file
您转换了节点上的seqnum
属性,CSV文件保持不变。
尝试MATCH
Contact
节点,查看该节点的值是否转换为int:
MATCH (c:Contact {cid: 'some_id_here', seqnum: 1} )
RETURN c