# Query Name and Version

## Syntax <a href="#synopsis" id="synopsis"></a>

```sql
CREATE [STREAM | CHANGELOG] relation_name
...
AS select_statement ...
QUERY WITH('query.name' = query_name);
```

## Description <a href="#description" id="description"></a>

Queries can be launched with an optional name by specifying the `query.name` property in the `QUERY WITH` block. This allows queries to be referred to by name in other commands like `DESCRIBE QUERY` and `TERMINATE QUERY`.

Query name must not conflict with the names of any other running queries within the Organization. However, it may reuse the name of a previously terminated query. Doing so will lauch the new query with the same name.

Each query is also assigned a version number. The first query to use a particular name is assigned version 1. The next query to reuse the name will get version 2 and so on.

The [LIST QUERIES](/reference/sql-syntax/command/list-queries.md) can be used to view the query name and version of running or terminated queries.

### Arguments <a href="#parameters" id="parameters"></a>

#### query.name

This specifies the unique query name to use when launching a query.

## Examples

#### Launch a named query

The following is an example of how to launch a Query with a name. Note the `Name` from `LIST QUERIES` is the same as the `query.name`.

```sh
demodb.public/demostore# CREATE STREAM demostream AS SELECT * FROM pageviews QUERY WITH('query.name' = demoquery);
+--------+--------------------------------------+----------+---------------------------------------------------------------------+
|  Type  |                 Name                 |  Command |                               Summary                               |
+--------+--------------------------------------+----------+---------------------------------------------------------------------+
| stream | demodb.public.demostream             | CREATE   | stream "demostream" was successfully created                        |
+--------+--------------------------------------+----------+---------------------------------------------------------------------+
| query  | 89f21634-39a0-44e4-979d-9f35017a8ca0 | CREATE   | query 89f21634-39a0-44e4-979d-9f35017a8ca0 was successfully created |
+--------+--------------------------------------+----------+---------------------------------------------------------------------+

demodb.public/demostore# LIST QUERIES;
+--------------------------------------+-----------+----------+-----------------+---------------+-------------------------------------------------------------------------------------------+----------+-------------------------------+-------------------------------+
|                  ID                  |    Name   |  Version |  Intended State |  Actual State |                                                           Query                           |   Owner  |           Created At          |           Updated At          |
+--------------------------------------+-----------+----------+-----------------+---------------+-------------------------------------------------------------------------------------------+----------+-------------------------------+-------------------------------+
| 89f21634-39a0-44e4-979d-9f35017a8ca0 | demoquery |        1 | running         | new           | CREATE STREAM demostream AS SELECT * FROM pageviews QUERY WITH('query.name' = demoquery); | sysadmin | 2024-07-30 20:00:01 +0000 UTC | 2024-07-30 20:00:05 +0000 UTC |
+--------------------------------------+-----------+----------+-----------------+---------------+-------------------------------------------------------------------------------------------+----------+-------------------------------+-------------------------------+
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/reference/sql-syntax/query/named-queries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
