EnMag
EnMag

Reputation: 83

large integers in cypher, neo4j

I have a dataset with some hexadecimal integers like '4726E440'. I want to add this numbers as attributes of the nodes. If I execute:

CREATE (n {id:toInt("4726E440")});

neo4j gives me this error:

integer, 4726E440, is too large

Is there any way to handle this kind of integers (other than saving them as strings)?

Upvotes: 0

Views: 2098

Answers (3)

B D T
B D T

Reputation: 83

Just to build on the other answers, you'll need to wrap your big number in the toInteger() in cypher. The following numbers should not equal one another, but Neo4j thinks they do. (Code was run in Neo4j v4.2, first via the browser interface and then using the python driver):

RETURN 2^63-2 AS Minus2, 2^63-1 AS Minus1, 2^63-2 = 2^63-1 AS Comparison
╒═════════════════════╤═════════════════════╤════════════╕
│"Minus2"             │"Minus1"             │"Comparison"│
╞═════════════════════╪═════════════════════╪════════════╡
│9223372036854776000.0│9223372036854776000.0│true        │
└─────────────────────┴─────────────────────┴────────────┘

But, if you convert the big number to an integer in the statement, Cypher reads it correctly:

RETURN toInteger(2^63)-2 AS Minus2, toInteger(2^63)-1 AS Minus1, toInteger(2^63)-2 = toInteger(2^63)-1 AS Comparison
╒═══════════════════╤═══════════════════╤════════════╕
│"Minus2"           │"Minus1"           │"Comparison"│
╞═══════════════════╪═══════════════════╪════════════╡
│9223372036854775805│9223372036854775806│false       │
└───────────────────┴───────────────────┴────────────┘

Upvotes: 0

TheHowlingHoaschd
TheHowlingHoaschd

Reputation: 706

If you are wondering what the actual limit for number size in Neo4J is, this forum post might interest you.

Basically, Neo4J uses signed 64bit integers with a maximum of 2**63 - 1. There seems to be no way to increase this limit at the moment, and you will have to resort to strings or byte lists if you really have to store numbers of this size.

Upvotes: 0

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

Not 100% sure, but this looks like you're trying to convert a string holding a floating point number 4724*10^440 to an int value. That one obviously is too large.

If you want to use hex literals you need to prefix them with 0x, e.g.

return toInt(0x4726E440)

returns 1193731136 - so it's still in range.

Upvotes: 1

Related Questions