Using the CALL Function in Neo4j for a subquery throws an error because of the '{' - neo4j

So i can use the CALL function in it's function as CALL procedure but when i try to invoke a subquery with CALL {} i get following Error:
Neo.ClientError.Statement.SyntaxError: Invalid input '{': expected whitespace, comment, namespace of a procedure or a procedure name (line 1, column 6 (offset: 5))
"CALL {}"
^
I have no idea what i'm doing wrong, i found this procedure in the docs. I'm using Neo4j Browser version: 3.2.15 and Neo4j Server version: 3.5.1 (community).
Thank you for your helping!

CALL with subquery was introduced in Neo4j 4.0, so the syntax doesn't exist in 3.5.1. You'll need to upgrade to 4.0+ to get the functionality you're after.

Related

Kuzzle-SDK-SearchResult query

I am currently trying to SearchResult query in kuzzle android sdk earlier it was working but after upgrading the version I have an error when I perform SearchResult I get following error : java.util.concurrent.ExecutionException: io.kuzzle.sdk.Exceptions.ApiErrorException: Wrong type for argument "from" (expected: integer)
Any idea of the reason ? Thanks
Actually the error message gives you the answer: Wrong type for argument "from" (expected: integer)
I suspect that your from argument is not an integer type.

Spring data neo4j: Invalid syntax '$' in Cypher。 How to replace '$' with '{}'?

The Cypher generated by spring data neo4j uses "$" to pass value, which will cause a error of Invalid Syntax by neo4j.
For example:
The Cypher generated by spring data neo4j for:
Optional<linkType> findById(Long id);
is
"MATCH ()-[r0:`linkType`]->() WHERE ID(r0)=$id WITH r0,STARTNODE(r0) AS n, ENDNODE(r0) AS m RETURN r0,n,m, ID(r0)"
This gets a error of Invalid Syntax.
I fixed this by use #Query:
#Query("MATCH ()-[r0:`linkType`]->() WHERE ID(r0)={id} WITH r0,STARTNODE(r0) AS n, ENDNODE(r0) AS m RETURN r0,n,m, ID(r0)")
Optional<linkType> findById(Long id);
However, when I want to use the PagingAndSortingRepository, I cannot use the #Query to fix this problem. Because it will add SKIP $sdnSkip LIMIT $sdnLimit at the edn automaticaly.
How can I fix this problem? Thanks.
You are using a really old version of neo4j (older than 3.0).
In neo4j 3.0, the {foo} syntax was deprecated in favor of the $foo syntax. In neo4j 4.0, the {foo} syntax was totally removed.
Instead of trying to support the obsolete {foo} syntax, you should upgrade your neo4j installation to a more recent (ideally, the latest) version of neo4j. If you have data to upgrade, you will have to upgrade in 2 steps:
From your current version to 3.5.
From 3.5 to 4.x.

Can I call a postgres "Procedure" (not "function") from java using the postgres JDBC driver?

I'm new to postgres but am attempting to call a procedure in Postgres 11 (new "procedure" not a "function"), calling from java as a spring SimpleJDBCCall (using Postgresql-42.2.5 jdbc driver). However, when I execute the procedure I am encountering the following exception:
org.springframework.jdbc.BadSqlGrammarException:
CallableStatementCallback; bad SQL grammar [{call
pa_test_schema.pr_dosomething(?)}]; nested exception is
org.postgresql.util.PSQLException: ERROR:
pa_test_schema.pr_dosomething(bigint) is a procedure Hint: To call a
procedure, use CALL. Position: 15 at
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1065)
at
org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1104)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:414)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:397)
at
org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:193)
My procedure code:
CREATE PROCEDURE pa_test_schema.pr_DoSomething
( P_input_ID IN inputs.input_ID%TYPE
) AS $$
BEGIN
-- do something
END;
$$ LANGUAGE plpgsql;
My java code:
SimpleJdbcCallOperations pr_DoSomething = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName("pa_test_schema")
.withProcedureName("pr_DoSomething");
Map<String, Object> inputs = Maps.newHashMap();
inputs.put("p_input_id", 123456);
pr_DoSomething.execute(inputs);
When I step through the code I can see the driver is modifying the sql of the callable statement to the syntax required for calling a postgres function:
select * from pa_test_schema.pr_dosomething(?) as result
This is the method in the driver that is doing this conversion:
https://github.com/pgjdbc/pgjdbc/blob/faab499853c56f67cb70fb242f75b918452f2a6f/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L766
I understand procedures were only introduced in Postgres 11 (previously one would have used void-returning functions) and have read through the postgres driver documentation but don't see any reference to calling procedures rather than functions.
Does this mean that the current postgres driver does not yet support this or is there another approach I should be using? Should I just be using postgres functions instead?
Currently (as of Postgres 11.1 and driver version 42.2.5) the standard JDBC approach using a CallableStatement cannot be used to call a stored procedure.
I don't really use Spring JDBC Template, but the following code works in plain JDBC and should be adaptable to Spring JDBC Tempalte:
Connection con = DriverManager.getConnection(...);
PreparedStatement pstmt = con.prepareStatement("call pa_test_schema.pr_DoSomething(?)");
pstmt.setInt(1, 42);
pstmt.execute();
Note that this uses Postgres' call command. Do not confuse this with the "{call ...}" syntax for a CallableStatement.
Some more details on why currently a CallableStatement does not work can be found in the JDBC mailing list here and here

Neo4j apoc procedures impala configuration

1) Downloaded the impala drivers 2.5.37 from
https://www.cloudera.com/downloads/connectors/impala/jdbc/2-5-37.html
2) Executed:
call apoc.load.driver("com.cloudera.impala.jdbc4.Driver")
No errors.
3) Executed:
CALL apoc.load.jdbc("jdbc:impala://<URL>:21050/default;user=<username>;password=<password>",
'<database>.<table name>') YIELD row
RETURN row.account as account_num
Error :Failed to invoke procedure apoc.load.jdbc: Caused by:
java.lang.RuntimeException: Cannot execute SQL statement `SELECT *
FROM .. Error: [Simba]ImpalaJDBCDriver
Error setting/closing session: {0}.
Can you please help me out?
The second argument to apoc.load.jdbc must be a string that is either a table name or a SQL statement. Replace '.' with the appropriate value (in your case, probably the name of the table that contains the account column).

postgres - operator does not exist: double precision ~~ unknown

ActionView::Template::Error (PG::UndefinedFunction: ERROR: operator
does not exist: double precision ~~ unknown
2016-04-10T23:45:59.506005+00:00 app[web.1]: LINE 1: ... =
"trackers"."category_id" WHERE (categories.tag LIKE '1.%'...
this is the error i get when i try to run this line of code here
Tracker.group(:category_id).joins(:category).where('categories.tag LIKE ? AND user_id = ?', "#{tag.to_i}.%", current_user.id)
tag is of type float, and i typecast it to an integer in order to check for tags 1.1, 1.2, 1.3 etc
so in the example above I type cast tag with value 1.0 to be 1, so i can search for tags that are like 1.1, 1.2 etc
I am using postgres on heroku that gives this error. locally i use sqlite3 and it works just fine.
how can i overcome this?
Since you're in rails, sort out the dynamic-ness in rails first then send that to the ORM. The syntax you provided already accepts any parameters (eg: WHERE tag between ? and ?), so before you request the data from the ORM, sort out in rails the high and lows. The query is already setup for something to be dynamic.

Resources