21.4 Run a PGQL Query

POST https://localhost:7007/v2/runQuery

Run one or multiple statements for the specified driver.

Version: v2

Request

Request Header

  • Accept: application/json; charset=UTF-8
  • Header: Authorization: Bearer <token>
  • Content-Type: application/json

Table 21-3 Request Body Parameters

Parameter Type Description Required
statements string [ ] One or multiple statements Yes
driver string Specifies the PGQL driver. The supported values are:
  • GRAPH_SERVER_PGX: To run PGQL queries against the graph server (PGX)
  • PGQL_IN_DATABASE: To run PGQL statements or queries against the database
  • SQL_IN_DATABASE: To run graph queries against the database
Yes
parameters object
  • dynamicSampling: integer
  • parallel: integer
  • start: integer
  • size: integer
Parameters include:
  • Dynamic Sampling Value
  • Degree of Parallelism
  • Fetch size (= the number of rows) of the query result
Parameters are all optional.
  • Default value for dynamic sampling is 2.
  • Default value for parallelism depends on the driver.
  • Default value for start is 0.
  • Default value for size is 100.
visualize boolean Flag to set visualization Optional. Default value is true.

Sample Request Body

{
  "statements": [
    "CREATE PROPERTY GRAPH test_graph VERTEX TABLES (regions KEY (region_id), countries KEY (country_id))EDGE TABLES (countries AS countries_regions SOURCE KEY ( country_id ) REFERENCES 
     countries(country_id) DESTINATION KEY (region_id) REFERENCES regions(region_id) NO PROPERTIES ) OPTIONS (pg_pgql)", 
    "SELECT v FROM MATCH (v) ON test_graph LIMIT 1"
  ],
  "driver": "PGQL_IN_DATABASE",
  "parameters": {
    "dynamicSampling": 2,
    "parallel": 8,
    "start": 0,
    "size": 100
  },
  "visualize": true

Response

  • 200 OK
  • Content-Type: application/json

Sample Response Body

{
    "results": [
        {
            "pgqlStatement": "CREATE PROPERTY GRAPH test_graph VERTEX TABLES (regions KEY (region_id), countries KEY (country_id))EDGE TABLES (countries AS countries_regions SOURCE KEY ( country_id ) REFERENCES \r\n     countries(country_id) DESTINATION KEY (region_id) REFERENCES regions(region_id) NO PROPERTIES ) OPTIONS ( pg_pgql)",
            "result": "Graph successfully created",
            "success": true,
            "error": null,
            "started": 1757333361782,
            "ended": 1757333362005
        },
        {
            "pgqlStatement": "SELECT v FROM MATCH (v) ON REGION_GRAPH LIMIT 1",
            "result": "{\"schema\":\"GRAPHUSER\",\"name\":\"TEST_GRAPH\",\"resultSetId\":\"\",\"graph\":{\"vertices\":[{\"id\":\"COUNTRIES(AR)\",\"properties\":{\"REGION_ID\":2,\"COUNTRY_ID\":\"AR\",\"COUNTRY_NAME\":\"Argentina\"},\"labels\":[\"COUNTRIES\"]}],\"edges\":[],\"numResults\":1,\"graphOwner\":\"GRAPHUSER\",\"graphName\":\"REGION_GRAPH\"},\"table\":\"V\\nCOUNTRIES(AR)\"}",
            "success": true,
            "error": null,
            "started": 1757333362005,
            "ended": 1757333362714
        }
    ]
}

cURL Example

curl --location --request POST 'https://localhost:7007/v2/runQuery' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
  "statements": [
    "CREATE PROPERTY GRAPH test_graph VERTEX TABLES (regions KEY (region_id), countries KEY (country_id))EDGE TABLES (countries AS countries_regions SOURCE KEY ( country_id ) REFERENCES 
     countries(country_id) DESTINATION KEY (region_id) REFERENCES regions(region_id) NO PROPERTIES ) OPTIONS ( pg_pgql)",
    "SELECT v FROM MATCH (v) ON test_graph LIMIT 1"
  ],
  "driver": "PGQL_IN_DATABASE",
  "parameters": {
    "dynamicSampling": 2,
    "parallel": 8,
    "start": 0,
    "size": 100  
  },
  "visualize": true
}'