简体   繁体   中英

Specifying the primitive type of a property in a Cypher CREATE clause

Contrary to what's possible with the Java API, there doesn't seem to be a way to specify whether a numeric property is a byte , short , int or long :

CREATE (n:Test {value: 1}) RETURN n

always seems to create a long property. I've tried toInt() , but it is obviously understood in the mathematical sense of "integer" more than in the computer data type sense.

Is there some way I'm overlooking to actually force the type?

We have defined a model and want to insert test data using Cypher statements, but the code using the data then fails with a ClassCastException since the types don't match.

If you run your cypher queries with the embedded API then you can provide parameters in a hashmap with the correctly typed values.

For remote users it doesn't really matter as it goes through JSON serialization back and forth which looses the type information anyway. So it is just "numeric".

Why do you care about the numeric type?

you can also just use ((Number)n.getProperty("value")).xxxValue() (xxx = int,long,byte)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM