1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-21 05:21:08 +03:00
Files
postgres/doc/src/sgml/ref/create_view.sgml
1998-09-22 15:48:03 +00:00

277 lines
6.2 KiB
Plaintext

<REFENTRY ID="SQL-CREATEVIEW">
<REFMETA>
<REFENTRYTITLE>
CREATE VIEW
</REFENTRYTITLE>
<REFMISCINFO>SQL - Language Statements</REFMISCINFO>
</REFMETA>
<REFNAMEDIV>
<REFNAME>
CREATE VIEW
</REFNAME>
<REFPURPOSE>
Constructs a virtual table
</REFPURPOSE>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
<DATE>1998-09-21</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
CREATE VIEW <REPLACEABLE CLASS="PARAMETER">view</REPLACEABLE>
AS SELECT <REPLACEABLE CLASS="PARAMETER">query</REPLACEABLE>
</SYNOPSIS>
<REFSECT2 ID="R2-SQL-CREATEVIEW-1">
<REFSECT2INFO>
<DATE>1998-09-21</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TITLE>
<PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<ReturnValue><replaceable class="parameter">view</replaceable></ReturnValue>
</TERM>
<LISTITEM>
<PARA>
The name of a view to be created.
</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>
<ReturnValue><replaceable class="parameter">query</replaceable></ReturnValue>
</TERM>
<LISTITEM>
<PARA>
An SQL query which will provide the columns and rows of the view.
</PARA>
<PARA>
Refer to the SELECT statement for more information
about valid arguments.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</REFSECT2>
<REFSECT2 ID="R2-SQL-CREATEVIEW-2">
<REFSECT2INFO>
<DATE>1998-09-21</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
</PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<replaceable>status</replaceable>
</TERM>
<LISTITEM>
<PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<ReturnValue>CREATE</ReturnValue>
</TERM>
<LISTITEM>
<PARA>
The message returned if the view is successfully created.
</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>
<ReturnValue>
WARN amcreate: "<replaceable class="parameter">view</replaceable>" relation already exists
</ReturnValue>
</TERM>
<LISTITEM>
<PARA>
This error occurs if the view specified already exists in the database.
</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>
<ReturnValue>NOTICE create: attribute named "<replaceable class="parameter">column</replaceable>" has an unknown type</ReturnValue>
</TERM>
<LISTITEM>
<PARA>
The view will be created having a column with an unknown type
if you do not specify it. For example, the following command gives
an error:
<programlisting>
CREATE VIEW vista AS SELECT 'Hello World'
</programlisting>
whereas this command does not:
<programlisting>
CREATE VIEW vista AS SELECT 'Hello World'::text
</programlisting>
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</REFSECT2>
</REFSYNOPSISDIV>
<REFSECT1 ID="R1-SQL-CREATEVIEW-1">
<REFSECT1INFO>
<DATE>1998-09-21</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
CREATE VIEW will define a view of a table. This view is
not physically materialized. Specifically, a query
rewrite retrieve rule is automatically generated
to support retrieve operations on views.
</PARA>
<REFSECT2 ID="R2-SQL-CREATEVIEW-3">
<REFSECT2INFO>
<DATE>1998-09-21</DATE>
</REFSECT2INFO>
<TITLE>
Notes
</TITLE>
<PARA>
Use the DROP VIEW statement to drop views.
</PARA>
</refsect2>
<REFSECT2 ID="R2-SQL-CREATEVIEW-4">
<REFSECT2INFO>
<DATE>1998-09-21</DATE>
</REFSECT2INFO>
<TITLE>
Bugs
</TITLE>
<para>
Currently, views are read only.
</para>
</REFSECT2>
<REFSECT1 ID="R1-SQL-CREATEVIEW-2">
<TITLE>
Usage
</TITLE>
<PARA>
Create a view consisting of all Comedy films:
</PARA>
<ProgramListing>
CREATE VIEW kinds AS
SELECT *
FROM films
WHERE kind = 'Comedy';
SELECT * FROM kinds;
code |title |did| date_prod|kind |len
-----+-------------------------+---+----------+----------+------
UA502|Bananas |105|1971-07-13|Comedy | 01:22
C_701|There's a Girl in my Soup|107|1970-06-11|Comedy | 01:36
</ProgramListing>
</REFSECT1>
<REFSECT1 ID="R1-SQL-CREATEVIEW-3">
<TITLE>
Compatibility
</TITLE>
<PARA>
</PARA>
<REFSECT2 ID="R2-SQL-CREATEVIEW-5">
<REFSECT2INFO>
<DATE>1998-09-21</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
SQL92 specifies some additional capabilities for the CREATE VIEW statement:
</PARA>
<synopsis>
CREATE VIEW <replaceable class="parameter">view</replaceable> [ <replaceable class="parameter">column</replaceable> [, ...] ]
AS SELECT <replaceable class="parameter">expression</replaceable> [AS <replaceable class="parameter">colname</replaceable>] [, ...]
FROM <replaceable class="parameter">table</replaceable>
[ WHERE <replaceable class="parameter">condition</replaceable> ]
[ WITH [ CASCADE | LOCAL ] CHECK OPTION ]
</synopsis>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
</TERM>
<LISTITEM>
<PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
CHECK OPTION
</TERM>
<LISTITEM>
<PARA> This option is to do with updatable views.
All INSERTs and UPDATEs on the view will be
checked to ensure data satisfy the view-defining
condition. If they do not, the update will be rejected.
</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>
LOCAL
</TERM>
<LISTITEM>
<PARA>
Check for integrity on this view.
</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>
CASCADE
</TERM>
<LISTITEM>
<PARA>
Check for integrity on this view and on any dependent
view. CASCADE is assumed if neither CASCADE nor LOCAL is specified.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>
</REFENTRY>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->