2014-09-01 62 views
0

有沒有辦法僅設置LIMIT,如果參數{limit}有數字值。Neo4j LIMIT如果參數已設置

... 
RETURN whatever 
LIMIT {limit} 

也許在這樣的方式(我知道,接下來的代碼示例不工作)

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

的感謝!

回答

1

您應該通過構建動態查詢來處理應用程序層中的邏輯。

編輯:

這可以簡單地像下面的例子來完成(在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 
+0

我都做到了這樣,但我會很樂意找一個查詢中的解決方案。不管怎麼說,還是要謝謝你。 – koschwitz 2014-09-01 21:15:53

+0

我已經爲您的應用程序層編輯了一個示例 – 2014-09-01 21:26:19