QUERY_GRAPH function
can be called either within a SELECT statement as a table function or within
an EXECUTE FUNCTION call.
Parameters
GRAPH
GRAPH
Name of the graph to query
QUERIES
QUERIES
Nodes or edges to be queried specified using the SQL
INPUT_TABLE or INPUT_TABLES function; review
Query Identifiers and Query Identifier Combinations for more information.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
ADJACENCY_TABLE
ADJACENCY_TABLE
Name of the table to store the resulting adjacent edges in
[schema_name.]table_name format, using standard
name resolution rules and meeting
table naming criteria; a table storing the resulting matching nodes will also
be created, named <ADJACENCY_TABLE>_nodesOnly applicable when using the
EXECUTE FUNCTION syntaxRINGS
RINGS
Sets the number of rings around (hops from) the queried node(s) to return matching edges & nodes
Only applicable when querying on nodes; e.g., giving
NODE_NAME or NODE_LABELRESTRICTIONS
RESTRICTIONS
Additional restrictions to apply to the nodes/edges of an existing graph specified using the SQL
INPUT_TABLE or INPUT_TABLES function; review Components and Identifiers and Identifier Combinations for more
information.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
Only applicable when querying on nodes; e.g., giving
NODE_NAME or NODE_LABELOPTIONS
OPTIONS
Optional indicator that a comma-delimited list of connection option/value assignments will follow.
| Option | Description |
|---|---|
and_labels | If true, the result of the query has entities that satisfy all the target labels instead of any of the labels. The default is false. |
find_common_labels | If true, adds a LABELS column to the output tables specified by ADJACENCY_TABLE. When RINGS is 0, all labels of queried nodes & edges will be listed in this column; otherwise, (for many-to-many queries and multi-level traversals), all common labels between the source & target nodes, as well as common edge labels in each path will be listed. The default is false. |
force_undirected | If true, all inbound & outbound edges relative to the node will be returned. If set to false, only outbound edges relative to the node will be returned. The default is false. Consult Directed Graphs for more details. Only applicable when querying on nodes on a directed graph |
limit | When specified, limits the number of query results. The size of the corresponding node table will also be limited by this value. |
output_charn_length | When specified, limits the size of string columns in the output tables. The default is 64. Valid values are between 1 & 256. |
output_wkt_path | If true, adds a QUERY_EDGE_WKTLINE column to the specified ADJACENCY_TABLE so the solution can be viewed via WMS; for social and non-geospatial solutions, the QUERY_EDGE_WKTLINE column will be populated with spatial coordinates derived from a flattening layout algorithm so the solution can still be viewed. The default is false. |
result_table_index | Indicates which result table to return results from:
Only applicable when using the table function syntax |
server_id | Indicates which graph server(s) to send the request to. Default is to send to the server, amongst those containing the corresponding graph, that has the most computational bandwidth. |
Examples
Using theEXECUTE FUNCTION syntax necessitates the ADJACENCY_TABLE
parameter to store the query results, where using the table function syntax will
return the results directly.
Querying by Hops
Queries can make use of aHOP_ID
identifier to match nodes & edges at a given
distance from the source node or edge.
A graph of movies and their actors & directors can be queried, for instance, to
return the titles & directors of movies in which James Spader has acted. Here,
the query starts with the James Spader actor node and uses HOP_ID filters
to:
- move across
actededges in the 1st hop to all the nodes in which James Spader has acted - find the director nodes connected to those movies in the 2nd hop; note the
-2for theHOP_IDallows one-way edges to be traversed in reverse—thedirectededge connecting directors to the movies they directed is one-way, from director to movie, but the query needs to move from movie to director of that movie, thus the-2designation for the 2nd hop to follow those edges in reverse
Query by Hop ID Example
Querying for Commonalities
Queries can make use of thefind_common_labels option to list labels shared
by both source & target node, as well as labels shared by edges in the result
paths.
A graph of movies and their actors & directors can be queried, for instance, to
return the common occupations within filmmaking between Al Pacino and those who
have directed movies in which he has acted. Here, the query starts with the Al
Pacino actor node, looks within two hops for directors
(Al Pacino->movie->directed by), and returns those directors along with
occupations shared by Al Pacino and each one:
Query for Common Labels Example
Supplementing Queried Graph Data
As graph queries ultimately produce standard SQL result sets, they can be used in larger SQL queries as joins or sub-selects to add data to result sets or to filter data out of them. A graph of movies and their actors & directors can be queried, for instance, to return the actors in Jean Reno movies, and that result can be joined with a table of actor biographical data to also return the ages of those actors. Here, the query starts with the Jean Reno actor node, looks within two hops for actors (Jean Reno->movie->acted in), and returns those actors along with their respective current ages by subtracting their corresponding date of birth (dob column) in the biographical table (person) from the current date:
Supplementing Graph Query Example