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

# GENERATE SQL

Creates a SQL query equivalent of the given natural-language question using the
specified [SQL-GPT context](https://docs.kinetica.com/content/sql/sqlgpt/create-context.md#sql-gpt-create-context).

```sql title="GENERATE SQL Syntax" theme={null}
GENERATE SQL FOR '<question>'
[WITH OPTIONS (<option name> = '<option value>'[,...])]
```

## Parameters

> [accordion] \<question>
>
> Natural-language question for which an equivalent SQL query will be generated

> [accordion] \<schema name>
>
> Name of the [schema](https://docs.kinetica.com/content/sql/ddl/create-schema.md#sql-create-schema) containing the *context* to use in generating
> the query

> [accordion] WITH OPTIONS
>
> Optional indicator that a comma-delimited list of SQL generation option/value assignments will
> follow.
>
> See [SQL Generation Options](https://docs.kinetica.com/content/sql/sqlgpt/generate-sql.md#sql-gpt-generate-sql-opts) for the complete list of options.

## SQL Generation Options

The following options can be specified to modify the way SQL queries are
generated.

> [accordion] ai\_api\_provider
>
> Name of an LLM service to use other than the default one; the default, `sqlgpt`, uses the
> Kinetica SQLGPT.io service.

> [accordion] ai\_api\_url
>
> URL of an LLM service to use other than the default one.

> [accordion] context\_name
>
> Name of the *SQL-GPT context* to use as a basis for generating SQL queries; should be of the
> form `[<schema name>.]<context name>`.

> [accordion] context\_names
>
> Comma-separated list of names of *SQL-GPT contexts* to use as a basis for generating SQL
> queries; each should be of the form `[<schema name>.]<context name>`, and the entire list
> should be single-quoted.
>
> For example:
>
> ```
> context_names = 'example.atc_ctx,example.nyctaxi'
> ```

> [accordion] use\_rag
>
> Whether to use [retrieval-augmented generation (RAG)](https://docs.kinetica.com/content/sql-gpt/concepts.md#sql-gpt-overview-rag) facilities
> with the given *SQL-GPT contexts* when processing this request.

## SQL Generation Examples

To generate the SQL equivalent query to a given question using the
`example.atc_ctx` *SQL-GPT context*:

```sql GENERATE SQL Example theme={null}
GENERATE SQL FOR
	'What is the callsign and position of the aircraft with most recent timestamp?'
WITH OPTIONS (context_name = 'example.atc_ctx')
```

To generate the SQL equivalent query to a given question using the
`nyctaxi_ctx` & `flights_ctx` *SQL-GPT contexts* with SQL RAG:

```sql GENERATE SQL with RAG Example theme={null}
GENERATE SQL FOR
	'What was the busiest airport, including taxis and flights, during January and February of 2023?'
WITH OPTIONS (context_names = 'nyctaxi_ctx, flights_ctx', use_rag = 'true')
```


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