# VIEW

Config path: `/<database>/<schema>/view/<name>.yaml`

Example:

```yaml
columns:
  aircraft_code: "Aircraft code, IATA"
  model: "Aircraft model"
  range: "Maximal flying distance, km"

text: |-
  SELECT ml.aircraft_code,
      lang(ml.model) AS model,
      ml.range
  FROM aircrafts_data ml

comment: >-
  Each aircraft model is identified by its three-digit code (aircraft_code).
  The view also includes the name of the aircraft model (model) and the maximal flying distance, in kilometers (range).
```

## Schema

* **columns** (dict)
  * *{key}* (ident) - column name
  * *{value}* (str) - column comment
* <mark style="background-color:red;">**text**</mark> (str) - view text
* **is\_secure** (bool) - is view secure
* **change\_tracking** (bool) - enable change tracking for this VIEW and underlying tables
* **depends\_on** (list)
  * *{items}* (ident) - names of other views which this view depends on
* **comment** (str)

## Policy reference parameters

* **aggregation\_policy** (dict)
  * **policy\_name** (ident) - name of [AGGREGATION POLICY](/basic/yaml-configs/aggregation-policy.md)
  * **columns** (list)
    * *{items}* (ident) - optional reference column names defining "entity"
* **join\_policy** (dict)
  * **policy\_name** (ident) - name of [JOIN POLICY](/basic/yaml-configs/join-policy.md)
  * **columns** (list)
    * *{items}* (ident) - optional allowed join keys
* **masking\_policies** (list)
  * *{items}* (dict)
    * **policy\_name** (ident) - name of [MASKING POLICY](/basic/yaml-configs/masking-policy.md)
    * **columns** (list)
      * *{items}* (ident) - reference column names
* **projection\_policies** (list)
  * *{items}* (dict)
    * **policy\_name** (ident) - name of [PROJECTION POLICY](/basic/yaml-configs/projection-policy.md)
    * **column** (ident) - reference column name
* **row\_access\_policy** (dict)
  * **policy\_name** (ident) - name of [ROW ACCESS POLICY](/basic/yaml-configs/row-access-policy.md)
  * **columns** (list)
    * *{items}* (ident) - reference column names

## Usage notes

1. Invalid views will be re-created automatically, even if view definition remains exactly the same.
2. If you want to access objects from another database in VIEW definition, and if you want to preserve [env prefix](/guides/other-guides/env-prefix.md) support for such views, please use the `env_prefix` [placeholder](/basic/yaml-placeholders.md).\
   \
   For example: `${{ env_prefix }}db_name.schema_name.object_name`.\
   \
   You may access objects in the same database by omitting database name altogether.
3. You may use [custom YAML tag](/basic/yaml-tag-include.md) `!include` to store view SQL text in a separate file instead of storing it inside YAML.

## Links

* [CREATE VIEW](https://docs.snowflake.com/en/sql-reference/sql/create-view.html)
* [SHOW VIEWS](https://docs.snowflake.com/en/sql-reference/sql/show-views.html)
* [DESC VIEW](https://docs.snowflake.com/en/sql-reference/sql/desc-view.html)
* [Parser & JSON Schema (GitHub)](https://github.com/littleK0i/SnowDDL/blob/master/snowddl/parser/view.py)


---

# 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.snowddl.com/basic/yaml-configs/view.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.
