> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thinkplatform.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Choose User guide for browser tasks, Developers for CLI, SDK and external agents, and Administration for organization management.
> Confirm identity and organization/project context before operations. Documentation access does not grant ThinkPlatform permissions.
> Review side effects, verify changes with a read, and do not blindly retry an operation with an uncertain outcome.
> Use documented UI steps for the web app and documented public CLI or SDK interfaces for automation. Follow each page’s prerequisites and authentication requirements.

# Execute and inspect Lakehouse statements

> Submit SQL, inspect completion, read result chunks, and cancel an unfinished statement.

These methods are available in **ThinkPlatform-client 0.6.133 and later**. Your project needs a configured SQL warehouse and permission for the intended operation. Select your project with a saved `work` profile as described in [Authentication](https://docs.thinkplatform.ai/cli/get-started/authentication.md).

## Submit a read-only statement

```python theme={"system"}
from thinkplatform.sdk import client_from_profile

with client_from_profile("work") as client:
    statement = client.lakehouse.statements.execute(
        "SELECT 1 AS example", wait_timeout="0s"
    )
    print(statement.statement_id, statement.status.state)
```

Save the returned ID. `wait_timeout="0s"` requests immediate submission status, so the statement may still be pending or running. The sample returns one value when successful; it does not create or change a table.

## Check status and read results

Set `THINKPLATFORM_STATEMENT_ID` to your returned ID, then inspect it in a later call:

```python theme={"system"}
import os
from thinkplatform.sdk import client_from_profile

with client_from_profile("work") as client:
    statement = client.lakehouse.statements.get(
        os.environ["THINKPLATFORM_STATEMENT_ID"]
    )
    print(statement.status.state)
    if statement.status.state == "SUCCEEDED":
        if statement.result is not None:
            print(statement.result.data_array)
            print("Next chunk:", statement.result.next_chunk_index)
    elif statement.status.error is not None:
        print(statement.status.error)
```

For the sample query, check that the successful result contains the value `1`. Native SQL results can represent numbers as strings. Inspect `manifest` for column and result metadata instead of assuming Python numeric types.

If `next_chunk_index` is present, call `client.lakehouse.statements.result_chunk(statement_id, next_chunk_index)` and continue using each returned next index. A first chunk is not a complete multi-chunk result. Bound polling and chunk collection for your application, and retain the statement ID if it does not finish within that bound. Avoid resubmitting SQL merely because a status or connection request timed out.

To request cancellation, call `client.lakehouse.statements.cancel(statement_id)`, then inspect the returned state and later status if necessary. A cancellation request does not prove a query stopped before all of its effects.

## Parameters and Hosted Apps

`execute()` also accepts typed `LakehouseStatementParameter` values and an optional `schema`; see the [API reference](https://docs.thinkplatform.ai/python-sdk/api-reference.md#lakehouse-statements). Bind untrusted values through parameters rather than interpolating them into SQL.

A Hosted App with `--lakehouse-read` uses the same statement methods through [request-bound SDK access](https://docs.thinkplatform.ai/python-sdk/hosted-apps.md). That grant is read-only and does not permit SQL writes. Inspect or poll only during a valid authenticated app request.

For recurring Databricks jobs, inspect `tp lakehouse jobs schedule --help`. It accepts a Quartz schedule, timezone, pause state, or explicit removal. This is a Lakehouse job schedule; [ThinkPlatform scheduled automations](https://docs.thinkplatform.ai/guides/automation/schedules-and-webhooks.md) are configured separately.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.