CYPHER: Converting String to Long

503 views
Skip to first unread message

Stacy Tyler Young

unread,
Nov 17, 2012, 4:25:01 PM11/17/12
to Neo4j
We inadvertently ended up storing dates as strings ...I had assumed Neo was storing as Long but realize now we should have annotated with @GraphProperty etc. We're running 1.8 ...from what I've gathered via the docs there is no way to cast to an int/long in a cypher query for comparing date ranges? :(

Stace 

Stacy Tyler Young

unread,
Nov 17, 2012, 4:26:38 PM11/17/12
to Neo4j
p.s. application is in production with existing data so we can't go back and add the appropriate GraphProperty. (SDN)

Wes Freeman

unread,
Nov 17, 2012, 4:46:19 PM11/17/12
to ne...@googlegroups.com
You're right. There's no way to cast from String to Long in Cypher--I think they'll probably add one soon, but it wouldn't be till later in 1.9 at least, which doesn't help you today. 

However, most dates stored as longs (either second or millisecond--since close to the end of 2001) have the same number of digits, so you can compare them as strings. Or do you have older dates you need to compare? Obviously, this is a kludge, but it won't stop working until year 2286 (assuming your dates are new).

Wes
 

On Sat, Nov 17, 2012 at 4:25 PM, Stacy Tyler Young <st...@actualcorp.com> wrote:
We inadvertently ended up storing dates as strings ...I had assumed Neo was storing as Long but realize now we should have annotated with @GraphProperty etc. We're running 1.8 ...from what I've gathered via the docs there is no way to cast to an int/long in a cypher query for comparing date ranges? :(

Stace 

--
 
 

Lasse Westh-Nielsen

unread,
Nov 19, 2012, 4:17:07 AM11/19/12
to ne...@googlegroups.com
Wes, nice thinking-outside-of-the-box there! :)

Stacy, if Wes' suggestion doesn't work I think you are left with a
classic data migration problem, unfortunately. With a schemaless DB
that should be a little easier that what you might be used to though?

Remind me, what is the default format of the Date-as-String that SDN
stores? Might be worth putting something in the backlog:
https://jira.springsource.org/browse/DATAGRAPH

- Lasse
> --
>
>

Stacy Tyler Young

unread,
Nov 19, 2012, 7:26:30 AM11/19/12
to ne...@googlegroups.com
Hi Lasse,

Date --> Date in ms as String. Curious as to why it would not default to long but there must be a reason.

Stace

--



Michael Hunger

unread,
Nov 19, 2012, 7:27:56 AM11/19/12
to ne...@googlegroups.com
Because initially there was only "to-string" conversion in SDN, so it stayed as the default.

Michael

--
 
 

Reply all
Reply to author
Forward
0 new messages