querywriter
role or greater (designer
, admin
, globaldesigner,
and superuser
) can create, install, and drop queries.queryreader
role or greater for a given graph can run the queries for that graph.INTERPRET QUERY
: execute the query's statements
POST /gsqlserver/interpreted_query
See the RESTPP API User Guide for details.
CREATE QUERY
: define the functionality of the queryINTERPRET QUERY
: execute the query with input values
CREATE QUERY
: define the functionality of the queryINSTALL QUERY
: compile the queryRUN QUERY
: execute the query with input valuesINTERPRET QUERY
and the appendix section Interpreted GSQL Limitations.CREATE QUERY
CREATE QUERY
defines the functionality of a query on a given graph schema.RETURNS
type (see Section "RETURN
Statement" for more details), optional specifiers for the output API and the language syntax version, and a body. The body consists of an optional sequence of typedefs
, followed by an optional sequence of declarations, then followed by one or more statements. The body defines the behavior of the query.FOR GRAPH graphName
is optional, as long as the graph has been specified already, either when entering gsql:
GSQL -g graphName [<gsql_command>]
or once inside the GSQL shell, by using the USE GRAPH graphName
command.
This is one aspect of Dynamic Querying.OR REPLACE
are included, then this query definition, if error-free, will replace a previous definition with the same query name. The new query will not be installed. That is,
CREATE OR REPLACE QUERY name
acts like
DROP QUERY name
CREATE QUERY name
However, if there are any errors in this query definition, then the previous query definition will be maintained. If the OR REPLACE
option is not used, then GSQL will reject a CREATE QUERY
command that uses an existing name.DISTRIBUTED
option applies only to installations where the graph has been distributed across a cluster. If specified, the query will run with a different execution model which may give better performance for queries that traverse a large portion of the cluster. For details, see Distributed Query Mode.​SELECT
, UPDATE
, INSERT
, DELETE
statements. The language supports conditional statements such as an IF
statement as well as looping constructs such as WHILE
and FOREACH
. It also supports calling functions, assigning variables, printing, and modifying the graph data.EDGE
or JSONOBJECT
): INT, UINT, FLOAT, DOUBLE, STRING, BOOL, STRING, DATETIME, VERTEX, JSONARRAY
SET<baseType>
, BAG<baseType>
Edge
and JSONOBJECT
INT
UINT
FLOAT
DOUBLE
STRING
BOOL
STRING
DATETIME
=
) after the parameter name and specify the default value:FOR GRAPH graphName
is optional, as long as the graph has been specified already, either when entering gsql:
GSQL -g graphName [<gsql_command>]
or once inside the GSQL shell, by using the USE GRAPH graphName
command.
SELECT
statements. Typically, the FROM
clause mentions the name of specific vertex types and edge types. String or string set parameters can be used for edge and target types instead.
getAttr
and setAttr functions, which take attribute name and data type as string parameters, can be used to parameterize attribute access.
INSERT
statements: If you are using INSERT
to add data to your graph, you need to specify what type of vertex or edge you want to add. This can also be parameterized.SELECT
, UPDATE
, INSERT INTO
, DELETE FROM
, and DELETE
statements.CREATE QUERY
is a query-body statement. If one of the statements is a CASE
statement with several THEN
blocks, each of the statements in the THEN
blocks is also a query-body statement. Each query-body statement ends with a semicolon.SELECT
statement, each of the statements in its ACCUM
clause is a DML-sub-statement. If one of those DML-sub-statements is a CASE
statement, each of the statement in the THEN
blocks is a DML-sub-statement.INTERPRET QUERY
INTERPRET QUERY
runs a query by translating it line-by-line. This is in contrast to the 2-step flow: (1) INSTALL
to pre-translate and optimize a query, then (2) RUN
to execute the installed query. The basic trade-off between INTERPRET QUERY
and INSTALL/RUN QUERY
is as follows:INTERPRET
:INSTALL
/RUN
:INSTALL
.INTERPRET
, from only a few percent faster to twice as fast.POST /gsqlserver/interpreted_query
. The query body is sent as the payload of the request. The syntax is like the Immediate query option, except that it is possible to provide parameters, using the query string of the endpoint's request URL. The example below shows a parameterized query using the POST /gsqlserver/interpreted_query
endpoint. For more details, see the RESTPP API User Guide.CREATE
is replaced with INTERPRET
.INTERPRET
statement. The INSTALL
and RUN
statements are not used.Create Query
section:RETURN
statement.uid
is set within the query.RUN
query, except RUN
is replaced with INTERPRET
.INSTALL QUERY
INSTALL QUERY
installs a query or multiple queries on a graph. Installing a query compiles the procedures described by the query as well as generates a REST endpoint for running the query. RUN QUERY
command as well as through its REST endpoint, both offering stronger performance as compared to running the query through the INTERPRET QUERY
command. The INSTALL QUERY
command will install the queries specified, with query names separated by a comma. INSTALL QUERY
command as the query itselfINSTALL QUERY
command installs multiple queries, each query is installed independently. If one query fails to be installed, it will not affect the installation of other queries. WRITE_QUERY
privilege on the graph where the query is to be installed or on the global scope. INSTALL QUERY
, using either of the following commands: INSTALL QUERY *
INSTALL QUERY ALL
INSTALL QUERY
commands are allowed as long as only one INSTALL QUERY
command is running on a single graph. Concurrent INSTALL QUERY
commands are not allowed on a single graph.INSTALL QUERY
-FORCE
-DISTRIBUTED
INSTALL QUERY -OPTIMIZE
INSTALL QUERY -OPTIMIZE
to optimize all installed queries. The names of the individual queries are not needed. This operation optimizes all previously installed queries, reducing their run times by about 20%. Optimize a query if query run time is more important to you than query installation time.RUN QUERY
command runs an installed query. To run a query with the RUN QUERY
command, specify the query name, followed by the query parameters enclosed in parentheses. Running a query executes all statements in the query body and produces output as specified by the output statements in the query. RUN QUERY
command:_
character for the value of the parameter. You can also omit parameters to use their default value. However, if you omit one parameter, you also have to omit all parameters that come after that parameter. name,
use _
in the place of the second parameter value:birthday
is not named in the parameter JSON object and therefore takes the default value:RUN QUERY
. More details about all parameter types are described in Section "Query Parameter Types".DATETIME
"YYYY-MM-DD HH-MM-SS"
"2019-02-19 19:19:19"
[1,5,10]
VERTEX<type>
vertex_id
person
and the desired ID is person2
.
"person2"
VERTEX
"person1"
and type="person
:
("person1","person")
VERTEX<type>
[ "person3", "person4" ]
VERTEX
[ ("person1","person"),("11","post") ]
DATETIME
"YYYY-MM-DD HH-MM-SS"
"2019-02-19 19:19:19"
["a", "list", "of", "args"]
VERTEX<type>
"id"
for the vertex ID and a field "type"
for the type of the vertex{"id": "person1",
"type": "person"}
VERTEX
(type not specified)"id"
for the vertex ID{"id": "person1"}
VERTEX<type>
VERTEX<type>
object[{"id": "person1"}, {"id": "person2"}]
VERTEX
[{"id": "person1",
"type": "person"},{"id": "person2",
"type": "person"}]
__GQUERY__USING_ALL_ACTIVE_MODE=true
in the query string of an HTTP request.RUN QUERY
command runs in the foreground and does not produce output until the query completes, which is inconvenient in the case of long-running queries. Starting with TigerGraph 3.1, you can run queries in Detached Mode to enable background execution of long-running queries.GSQL-TIMEOUT
header.-async
option for theRUN QUERY
command:request_id
):GSQL-ASYNC
header and set its value to true. If the query takes parameters, put them in the query string: /query_status
and the /query_result
RESTPP endpoints. "version"
. The "version"
value is an object with the following fields:api
edition
schema
CREATE GRAPH
statement is executed, the version is initialized to 0. Each time a SCHEMA_CHANGE JOB
is run, the schema value is incremented by 1 (e.g., 1, 2, etc.).SHOW QUERY query_name
. The query_name
argument can use *
or ?
wildcards from Linux globbing, or it can be a regular expression when preceded by -r
. See SHOW: View Parts of the Catalog​ls
GSQL command lists all created queries and identifies which queries have been installed.DROP QUERY query_name
. The query will be uninstalled (if it has been installed) and removed from the dictionary. The GSQL language will refuse to drop an installed query if another query is installed which calls query Q. That is, all calling queries must be dropped before or at the same time that their called subqueries are dropped.DROP QUERY ALL
DROP QUERY *