cypher cast string to integer in Agensgraph

36 Views Asked by At

I use the following query, this returns string values:

MATCH (n:artefact) RETURN (n.id)

I'm trying to cast the string to an integer, so I use the following:

MATCH (n:artefact) RETURN toInteger(n.id)

This returns the error:

[FAIL] BadSqlGrammarException->StatementCallback; bad SQL grammar [MATCH (n:artefact) RETURN toInteger(n.id);]; nested exception is org.postgresql.util.PSQLException: ERROR: function tointeger(jsonb) does not exist

Hint: No function matches the given name and argument types. You might need to add explicit type casts.

I've also tried toInt()

I'm guessing the function tointeger(jsonb) does not exist is the issue, is it trying to convert the entire jsonb in an integer rather than just the n.id?

How do I resolve this?

I'm using Agensgraph, when I start agens browser it states check version of AgensGraph ... v1.2 or under

1

There are 1 best solutions below

0
On

thank you for this question.

The function toInteger(string) to cast only a string (not the entire jsonb) to integer has been added to Agensgraph. If you want to supress any potential errors with casting, you could also use the toIntegerOrNull() function.

It will be part of the new release, but the release is in progress and will be done soon. In the meantime, you can install Agensgraph from the source code (v2.13 branch).

With this, the cypher query:

MATCH (n:artefact) RETURN toInteger(n.id) 

will cast it to integer.