繁体   English   中英

Neo4j LIMIT如果设置了参数

[英]Neo4j LIMIT if parameter is set

如果参数{limit}具有数值,则只能设置LIMIT

...
RETURN whatever
LIMIT {limit}

也许以这种方式(我知道,下一个代码示例不起作用)

...
RETURN whatever
if({limit}>0)
  LIMIT {limit}

谢谢!

您应该通过构建动态查询在应用程序层中处理此逻辑。

编辑:

可以像下面的示例一样简单地完成(在php中,但在所有语言中都可以)

public function doMatchQuery($limit = null)
{
    $query = 'MATCH (n) RETURN n';
    if ($limit && $limit !== 0) {
      // extend the query string
      $query .= ' LIMIT '.$limit;
    }
}

// Calling your function
$matchAll = $this->doMatchQuery(); // Return all n elements from the db
$matchFirstTen = $this->doMatchQuery(10); // Return the n elements with a limit of 10

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM