備註
這項功能目前處於公開預覽狀態。 正式運作之前,功能和語法可能會變更。
函 graph 式是一個內建函式,可查詢保存的圖形實體,類似於 cluster()、 database()、 external_table()和函 table() 式。 它支援擷取圖形的最新快照集、特定快照集,或從模型建立暫時性圖形。
權限
若要執行此函式,使用者需要 資料庫查看器許可權。
語法
graph(
GraphName)
graph(
GraphName,SnapshotName)
graph(
GraphName,snapshot=SnapshotName)
graph(
GraphName,短暫的)
參數
| 名稱 | 類型 | 為必填項目 | 說明 |
|---|---|---|---|
| GraphName | string |
✔️ | 要查詢的 圖表模型 名稱。 |
| SnapshotName | string |
要擷取的特定快照集名稱。 如果未指定,則會使用最新的快照集。 | |
| 暫時性 | bool |
如果 true為 ,則會從模型建立暫時性圖表(不使用快照集)。 如果 false為 ,則使用最新的快照集(與省略此參數相同)。 |
退貨
函 graph 式會傳回圖表,且後面必須接著 圖形運算符。 函式會擷取指定的圖形模型名稱,其中一個為:
- 最新的快照集 (預設值或指定時機
false) - 特定具名快照集
- 來自模型的暫時性圖形(指定時
true)
範例
查詢最新的快照集
下列範例會查詢名為 「SecurityGraph」 之保存圖形的最新快照集:
graph("SecurityGraph")
| graph-match (user)-[permission]->(resource)
where user.type == "User" and resource.type == "Database"
project UserName = user.name, ResourceName = resource.name, Permission = permission.type
查詢特定快照集
下列範例會查詢圖表的特定快照集:
graph("SecurityGraph", "Snapshot_2025_05_01")
| graph-match (attacker)-[attacks]->(target)-[connects]->(system)
where attacker.name == "MaliciousActor"
project Attacker = attacker.name, Target = target.name, System = system.name
使用具名參數語法進行查詢
下列範例會使用具名參數語法來指定快照集:
graph("SecurityGraph", snapshot="Snapshot_2025_05_01")
| graph-shortest-paths (start)-[e*1..20]->(end)
where start.name == "Alice" and end.name == "Database"
project PathLength = array_length(e), Path = e
從模型建立暫時性圖形
下列範例會從模型建立暫時性圖表,類似於 make-graph 運算符:
graph("SecurityGraph", true)
| graph-match (user)-[permission]->(resource)
where user.type == "User" and resource.type == "Database"
project UserName = user.name, ResourceName = resource.name, Permission = permission.type
使用 false 指定最新的快照集
下列範例會明確指定 false 使用最新的快照集,這相當於省略第二個參數:
graph("SecurityGraph", false)
| graph-match (user)-[permission]->(resource)
where user.type == "User" and resource.type == "Database"
project UserName = user.name, ResourceName = resource.name, Permission = permission.type