4

I've got three queries that are combined with a UNION clause:

CYPHER 2.0
START user=node:User(Id="2")
MATCH (user)-[:FOLLOWS_USER]->()-[:SHARES]->(post)-[?:ORIGINAL]->(original)
WHERE original is null
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
UNION
MATCH (user)-[:FOLLOWS_USER]->()-[:LIKES]->(post)
WITH post, count(post) as likes
WHERE likes >= 0
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
UNION
MATCH (user)-[:FOLLOWS_USER]->()-[:SHARES]->(post)-[repost:ORIGINAL]->()
WITH post, count(repost) as reposts
WHERE reposts >= 0
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
ORDER BY post.CreationTime desc
SKIP 0
LIMIT 100;

I want the SKIP, the LIMIT and the ORDER BY to apply to the whole result set, instead of the individual queries. I believe that's also the way it works in SQL. I think, however, that this is not the case in Neo4j, since I can just drop desc from the ORDER BY and the order remains the same.

Is this the intended behaviour? Is there a way I can write the query so that I can apply the SKIP, the LIMIT and the ORDER BYto the whole result set?

I'm also not sure if I have to repeat the line START user=node:User(Id="2") in each of the subqueries, since a query in 2.0 can start without a START clause. Do I have to repeat it?

Neo4j documentation is bit vague on the UNION keyword, IMHO.

Jan Van den bosch
  • 3,542
  • 3
  • 26
  • 38

1 Answers1

1

this is not yet supported, since before that there needs to be support for subqueries in order to implement things correctly.

Peter Neubauer
  • 6,311
  • 1
  • 21
  • 24
  • Oh, that's unfortunate. At least I can send multiple queries in a single HTTP request. Thanks anyway. – Jan Van den bosch Oct 23 '13 at 11:44
  • What is the status on post-UNION processing so that SKIP, LIMIT, ORDER BY works on the whole result set instead of the individual queries? – JeffA Oct 14 '14 at 06:06