# Approve a database query in GPTree

Where a waiting database query appears, how to read its plain-words description and warnings before you select Run query or Cancel, who approves under each setting, and what to do after it runs.

When a question asks a connected database for a number, GPTree prepares a read-only query and waits. Nothing runs until the query is approved. This guide covers where to find a waiting query, how to read it, and what happens after you decide.

## Where waiting queries appear

1. Open Settings, then Knowledge sources.
2. In the "Databases" section, look under "Queries waiting".

Queries are approved here, not inside the chat conversation. GPTree does not send an email when a query is waiting, so look in this list when you are expecting one.

While a query waits, the answer in chat is built from documents and says that the figure is not available yet and why.

## Read the query before you run it

Each waiting query shows:

1. **The question** that was asked.
2. **The query in plain words**: what is measured, from which table, and over which exact dates.
3. **Any warnings.** One example is a join that could count rows twice.
4. **The query itself**, behind "Show the query".

You do not need to read the query to decide well. The plain-words description and the warnings come first so that you can check two things:

- Is that the right table?
- Are those the right dates?

If "what did we sell last month" is about to be measured from a table you do not recognise, or over dates that are not last month, select "Cancel". If there is a warning, read it before anything else.

## Run it or cancel it

- **"Run query"** runs the query.
- **"Cancel"** drops it, and nothing runs.

A request to approve expires after 24 hours.

"Cancel" is for a query that is still waiting. A query that is already running on the database server cannot be cancelled. It is held to a time limit the database server enforces: 30 seconds by default and 60 at most.

## Who approves

That depends on the "What GPTree may read" setting on the connection.

| Setting | Who approves |
| --- | --- |
| "Views only" (the default) | The person asking approves their own query. |
| "Tables" | An admin of the connection approves each query. |
| "Defined metrics only" | A one-off query cannot run. GPTree answers only from metrics the organisation has defined and checked. |

## After the query runs

Ask the question again. The answer now includes the figure, cites the saved result, and states the exact range it measured.

The figure does not arrive in the conversation by itself after approval. Asking again is what brings it in. Asking the same question again within five minutes reuses the result instead of running the query twice.

## Questions GPTree may ask back

Some questions can be read more than one way. GPTree asks instead of guessing:

- **Which database?** If two connected databases both have the table, it asks which database.
- **Which date?** If the table has two dates, such as an order date and a ship date, it asks which one the period means.

A period such as "last month" is turned into exact dates by code, not by an AI model, in the time zone set on the connection. If a period cannot be turned into exact dates, GPTree does not guess. It says so.

## Approving through the Knowledge API

A Knowledge API token needs the "Run database queries" permission to approve a query. A token that can only read or ask cannot cause a query to run.

## Related

- [Connect a database to GPTree](/learn/connect-a-database-to-gptree)
- How GPTree runs queries on your data safely
