Cypher: comparing properties with multiple types

69 views
Skip to first unread message

Aseem Kishore

unread,
Apr 3, 2013, 7:53:49 AM4/3/13
to Neo4j Discussion
We're giving our nodes a `usedAt` property whose type can vary:

- If the node has been "used", the property is a timestamp -- e.g. an int.

- If the node hasn't been "used", the property is false -- i.e. a boolean.

This presents a problem using Cypher today: we're unable to perform queries that compare that property.



It'd be nice if Neo4j supported flexible typing like this. E.g. in this case:

- ORDER BY could order types just as it orders values, e.g. nulls before booleans before ints before strings.

- WHERE could support a function for querying the property's type, e.g. TYPE(n.usedAt) = 'number', so that we could properly filter before comparing.

Thanks!

Aseem

Michael Hunger

unread,
Apr 3, 2013, 8:56:44 AM4/3/13
to ne...@googlegroups.com
I like the type() function

As a workaround I'd suggest for now:

not to have a property for not used items. after all you can check for property existence when querying

Or coerce them all into strings

Sent from mobile device
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Wes Freeman

unread,
Apr 3, 2013, 11:24:33 AM4/3/13
to ne...@googlegroups.com
Yeah, as Michael says, use str()?


Wes

Aseem Kishore

unread,
Apr 3, 2013, 1:59:03 PM4/3/13
to Neo4j Discussion
STR() is an interesting workaround. (I wasn't aware of it since it's post-1.8.) It's not really a substitute, as it's too error-prone for general usage, but can work for now. Thanks.

Removing the property would work in this particular case, but not in others we're exploring, e.g. enabledAt = (timestamp if this node is to be considered enabled at some point, OR false if this node should be disabled [e.g. abuse], defaulting to true if missing).

TYPE() for properties would solve this for us. Thanks guys!

Aseem

Wes Freeman

unread,
Apr 3, 2013, 2:01:35 PM4/3/13
to ne...@googlegroups.com
Agree, +1 for Type()! Wouldn't be too hard, either. Maybe I'll do it.

Wes

Wes Freeman

unread,
Apr 3, 2013, 2:14:37 PM4/3/13
to ne...@googlegroups.com
We also need an Int() and Float() and Bool() to try to cast things, imo.

Wes
Reply all
Reply to author
Forward
0 new messages