/db2whrest/v1/sql_query_async?<sql>: GET

Gets data from a database asynchronously with an SQL query in a GET command.

You can use any standard SQL query. You must include the SQL query as a parameter of the URL. To send the query in an HTTP message body, see /db2whrest/v1/sql_query_async: POST. The following table shows which roles can access this REST API endpoint:
Table 1. Access by role
Data admin Data user Collection Admin Admin Service user
1 1 Χ Χ
1The search is restricted to documents that are tagged with collections to which the user ID has a datauser role assigned.

The asynchronous endpoints are useful alternatives in situations where the operation takes a long time to complete or has a negative effect on the overall performance of the system. For more information, see the topic Asynchronous endpoints.

Synopsis of the request URL

curl -k -H 'Authorization: Bearer <token>' https://<spectrum_discover_host>/db2whrest/v1/sql_query_async?<sql_statements> -X GET

Supported request types and response formats

Supported request types:
  • GET
Supported response formats:
  • CSV
  • JSON

Examples

  1. The following example shows how to get data from a database asynchronously with an SQL query in a GET command. The SQL query is included as a parameter of the URL.
    1. Submit the request. The endpoint responds by displaying the field {"status": "work scheduled"} to indicate that the operation is running asynchronously.
      curl -k -H 'Authorization: Bearer <token>' https://<spectrum_discover_host>/db2whrest/v1/sql_query_async?select%20*%20from%20datasrv04%20where%20owner%3D%27root%27 -X GET 
      {"status": "work scheduled"}
      The synchronous response to the request contains information about the asynchronously running task. The following is an example. For more information, see the topic Asynchronous endpoints.
      * HTTP 1.0, assume close after body
      < HTTP/1.0 202 ACCEPTED
      < Content-Type: text/html; charset=utf-8
      < Content-Length: 28
      < Location: https://<spectrum_discover_host>/db2whrest/v1/task_status/25b2df40-8f0c-4e32-a2f9-999ff3b18ada 
      < Server: Werkzeug/0.14.1 Python/3.4.5
      < Date: Thu, 15 Feb 2018 20:37:10 GMT
      
    2. Later, poll the URL that is provided in the Location field of the synchronous response header in Step (a).
      curl -k -H 'Authorization: Bearer <token>' https://<spectrum_discover_host>/db2whrest/v1/
      task_status/25b2df40-8f0c-4e32-a2f9-999ff3b18ada
    3. When the operation is complete, the endpoint displays the rows of data that are returned in response to the SQL query in the request. In the following example only the first two rows of output are shown:
      0,reflib,INDEX,SCAN,MO1,,Spectrum Scale,reflib.university.edu,3067343,root,root,
      -rw-r--r--,root,9,10,/reflib/cellranger-2.0.0/refdata-cellranger-ercc92-1.2.0/star/,
      sjdbList.out.tab,tab,resdnt,NA,2016-11-14 19:40:10,2017-06-02 21:30:26,
      2017-06-02 21:30:26,2018-07-24 16:32:47,system,0,1,reflib.university.edureflib3067343,
      ,,,,,,,,,,,,,,,
      .......
      1,reflib,INDEX,SCAN,MO1,,Spectrum Scale,reflib.university.edu,3067333,root,root,
      -rw-r--r--,root,9,10,/reflib/cellranger-2.0.0/refdata-cellranger-ercc92-1.2.0/star/,
      chrLength.txt,txt,resdnt,NA,2016-11-14 19:40:10,2017-06-02 23:28:21,
      2017-06-02 21:30:26,2018-07-24 16:32:47,system,412,1,reflib.university.edureflib3067333,
      ,,,,,,,,,,,,,,,
      ...