Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-14-2022 06:30 AM
Hi All,
I am trying to execute a Postgres SQL query through:
apoc.load.jdbcParams
and I try to give it an Array as a parameter like this:
WITH "select * from data.table where id = ANY(?)" as sql
CALL apoc.load.jdbcParams("jdbc:postgresql://db/testdb?user=test&password=*****&prepareThreshold=1",
sql, [['f1e245b9-e902-43d4-b3ea-01c5d8c89ac7','e3d5665b-b3b0-4d19-bf78-4c722ae394ae']])
YIELD row
Failed to invoke procedure `apoc.load.jdbcParams`: Caused by: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.ArrayList. Use setObject() with an explicit Types value to specify the type to use.
10-14-2022 08:28 AM
From what I read, the argument for 'ANY' is a subquery. Try changing the predicate to 'id IN ?'
10-17-2022 04:09 AM
Thank you @glilienfield for your answer!
I tried a few more things and the best I got to at the moment is this:
WITH "select id from data.table where id::text IN (?,?)" as sql
CALL apoc.load.jdbcParams("jdbc:postgresql://db/db?user=test&password=****&prepareThreshold=1", sql,
['f1e245b9-e902-43d4-b3ea-01c5d8c89ac7','c9b495eb-b90f-4435-8a8e-5b11f10676e6'])
YIELD row
MATCH (n:GenericNode)
WHERE n.id in [row.id]
CALL apoc.path.subgraphNodes(n, {relationshipFilter: ":Parent>",
minLevel: 0,
maxLevel: -1}) YIELD node
return node.id;
And we would like to pass in an arbitrary amount of ID's into the query. Would the APOC team be open for patches that would allow this?
Many thanks in advance,
Thomas
10-17-2022 10:43 AM
The 'IN' clause accept a list of values, although Oracle has a limit of 1000 elements per IN clause. Have you tried something like this. Here the first and only element of the parameters array is a list itself.
WITH "select id from data.table where id::text IN ?" as sql
CALL apoc.load.jdbcParams("jdbc:postgresql://db/db?user=test&password=****&prepareThreshold=1", sql,
[['f1e245b9-e902-43d4-b3ea-01c5d8c89ac7','c9b495eb-b90f-4435-8a8e-5b11f10676e6']])
YIELD row
MATCH (n:GenericNode)
WHERE n.id in [row.id]
CALL apoc.path.subgraphNodes(n, {relationshipFilter: ":Parent>",
minLevel: 0,
maxLevel: -1}) YIELD node
return node.id;
.
All the sessions of the conference are now available online