<commit_before>.. highlight:: psql
.. _ref-create-view:

===============
``CREATE VIEW``
===============

Define a new view.

.. rubric:: Table of Contents

.. contents::
    :local:

Synopsis
========

::

    CREATE [ OR REPLACE ] VIEW view_ident AS query


Where ``query`` is a :ref:`SELECT statement <sql_reference_select>`.


Description
===========

CREATE VIEW creates a named definition of a query. This name can be used in
other statements instead of a table name to reference the saved query
definition. A view is not materialized, instead the query is run every time a
view is referenced in a query.

If ``OR REPLACE`` is used, an already existing view with the same name will be
replaced.

If a schema name is given in the ``view_ident`` (``some_schema.view_name``),
the view will be created in the specified schema.

Table and view names must be unique within a schema. A view cannot have the
name of an already existing table.

Views are read-only. They cannot be used as a target relation in write
operations.


.. note::

    Currently not all supported ``SELECT`` statements can be used in a view
    definition. Using queries involving a JOIN, UNION or subqueries will result
    in an error on ``CREATE VIEW``

.. SEEALSO::

    :ref:`ref-drop-view`
<commit_msg>docs: remove note about limitations of views<commit_after>.. highlight:: psql
.. _ref-create-view:

===============
``CREATE VIEW``
===============

Define a new view.

.. rubric:: Table of Contents

.. contents::
    :local:

Synopsis
========

::

    CREATE [ OR REPLACE ] VIEW view_ident AS query


Where ``query`` is a :ref:`SELECT statement <sql_reference_select>`.


Description
===========

CREATE VIEW creates a named definition of a query. This name can be used in
other statements instead of a table name to reference the saved query
definition. A view is not materialized, instead the query is run every time a
view is referenced in a query.

If ``OR REPLACE`` is used, an already existing view with the same name will be
replaced.

If a schema name is given in the ``view_ident`` (``some_schema.view_name``),
the view will be created in the specified schema.

Table and view names must be unique within a schema. A view cannot have the
name of an already existing table.

Views are read-only. They cannot be used as a target relation in write
operations.

.. SEEALSO::

    :ref:`ref-drop-view`

{'fraction_non_alphanumeric': 0.1142737547090833, 'fraction_numerical': 0.0, 'mean_word_length': 3.838056680161943, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1680599', 'n_tokens_mistral': 685, 'n_tokens_neox': 651, 'n_words': 342}