Skip to content

SQL API

  • Not supported: files (GET, PUT), SP that results in Arrow format (even if called indirectly)
  • Supported only for multi-statement requests: transaction (COMMIT, ROLLBACK, BEGIN), Context (USE, ALTER SESSION), set session variables, create temporary objects
  • authentication: OAuth. Key-pair (using JWT) or PAT
  • end-points:
    • POST /api/v2/statements: submit a new request
    • /api/v2/statements/<handle>
    • /api/v2/statements/<handle>/cancel
  • header:
    • Authorization: Bearer <token>
    • (optional) X-Snowflake-Authorization-Token-Type: {OAUTH | KEYPAIR_JWT | PROGRAMMATIC_ACCESS_TOKEN}
    • Snowflake-Account: <account_locator> (required if using <org>-<acct> style URL and OAUTH)
    • Accept: application/json
  • body:
    • (required) statement: a SQL statement, or multiple SQL statements separated by ;
    • bindings: a json object with position as key e.g. {"1": {"type": "FIXED", "value": "123"}}
    • optional: database, schema, role, warehouse
    • query parameters: requestId=<uuid>, retry=true allow Snowflake to detect and skip duplicate query execution
    • Status: 200:
      • single statement executed synchronously, successfully and a ResultSet object containing data (array or arrays)
      • multi statement request ResultSet contains statementHandles array containing handles for each statements
    • Status: 202 statement submitted for async execution, either because explicitly requested or took more than 45 seconds and a QueryStatus object is returned that contains statementHandle
    • resultSet contains resultSetMetaData containing a list of partitionInfo
      • keep polling until either 200 or 4xx/5xx return code.
      • first response includes the first or only partition in data. Retrieve subsequent results with partition=<num> until no more partitions left
      • data contains array of array (row)
      • SQL NULL is represented by JSON null
  • multiple statements: executed as a transaction if all specified in a single HTTP request; must use begin and commit
    • statement: multiple SQLs separated by ;
    • count of statements as "parameters": {"MULTI_STATEMENT_COUNT": "<n>"}; count of 0 for unknown number of statements
    • no support for bound variables

REST/Python API

  • REST API to manage resources: accounts, users, roles, databases, schemas, tables, views etc.
  • Python API provide Pythonic way to manage Snowflake resources and collections
    • starts with Root(<connection>) object from snowflake.core package