3

I have a query of this form creating a new node in neo4j:

cypher.get_or_create_indexed_node(index="person", key="name", value="Fred", properties={"level" : 1}

However, when I query Fred to inspect his properties, his level = "1" /with quotes/. It appears something is converting his value to a string. This wouldn't matter much---I could convert it on retrieval if necessary---except when I try to do cypher queries like...

start b = node:person("*:*") RETURN b.level, ID(b) ORDER BY b.level desc SKIP 5 LIMIT 5;

...I notice that b.level is not being ordered as expected. I'm seeing something like:

==> +-------------------------+
==> | b.level         | ID(b) |
==> +-------------------------+
==> | "3"             | 42    |
==> | "0"             | 53    |
==> | "2"             | 57    |
==> | "0"             | 63    |
==> | "2"             | 20    |
==> +-------------------------+

when I expect something like:

==> +-------------------------+
==> | b.level         | ID(b) |
==> +-------------------------+
==> | 3               | 42    |
==> | 2               | 20    |
==> | 2               | 57    |
==> | 0               | 63    |
==> | 0               | 53    |
==> +-------------------------+

I assume this is a data-type issue, since the reference manual shows skip/limit functionality.

Is it the case that all values are strings, or that there's something else I should add to input correctly?

Mittenchops
  • 18,633
  • 33
  • 128
  • 246

1 Answers1

4

This should not be the case, numeric properties are fully supported. I am also not able to recreate the scenario using the following test:

def test_get_or_create_indexed_node_with_int_property(self):
    graph_db = neo4j.GraphDatabaseService()
    fred = graph_db.get_or_create_indexed_node(index="person", key="name", value="Fred", properties={"level" : 1})
    assert isinstance(fred, neo4j.Node)
    assert fred["level"] == 1
    graph_db.delete(fred)

I notice that you have prefixed the get_or_create_indexed_node method with cypher - I would not expect this since the cypher module does not have such a method. I would instead expect it to be either something like graph_db or batch. Maybe this is a typo?

Maybe you could share some more of your surrounding code? Something else around it may be affecting your results.

Nige

Nigel Small
  • 4,475
  • 1
  • 17
  • 15
  • I'm a dummy, I had actually created this example as a minified version of what was causing the problem. This works fine, the original didn't because I had somewhere defined my input as a string, rather than an integer. I don't know SO practices on this, but that definitely answers my title question. If I'm still having problems with the sort function after I refactor that, I may split that into a second question. – Mittenchops Dec 12 '12 at 22:30
  • Yeah, that's the right answer and both problems are solved. I misdiagnosed my problem with skip and limit. Fixing the types did fix that, too, and also good to know types work correctly. Thanks! – Mittenchops Dec 13 '12 at 09:23