1999-07-22 17:09:15 +02:00
|
|
|
<!--
|
2000-03-27 19:14:43 +02:00
|
|
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_view.sgml,v 1.9 2000/03/27 17:14:42 thomas Exp $
|
1999-07-22 17:09:15 +02:00
|
|
|
Postgres documentation
|
|
|
|
-->
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refentry id="SQL-CREATEVIEW">
|
|
|
|
<refmeta>
|
1999-07-22 17:09:15 +02:00
|
|
|
<refentrytitle id="SQL-CREATEVIEW-TITLE">
|
1998-09-01 17:53:09 +02:00
|
|
|
CREATE VIEW
|
1999-07-06 19:16:42 +02:00
|
|
|
</refentrytitle>
|
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
<refnamediv>
|
|
|
|
<refname>
|
1998-09-01 17:53:09 +02:00
|
|
|
CREATE VIEW
|
1999-07-06 19:16:42 +02:00
|
|
|
</refname>
|
|
|
|
<refpurpose>
|
|
|
|
Constructs a virtual table
|
|
|
|
</refpurpose>
|
1998-12-29 03:24:47 +01:00
|
|
|
</refnamediv>
|
1999-07-06 19:16:42 +02:00
|
|
|
<refsynopsisdiv>
|
|
|
|
<refsynopsisdivinfo>
|
2000-03-27 19:14:43 +02:00
|
|
|
<date>2000-03-25</date>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsynopsisdivinfo>
|
|
|
|
<synopsis>
|
1999-07-22 17:09:15 +02:00
|
|
|
CREATE VIEW <replaceable class="PARAMETER">view</replaceable> AS SELECT <replaceable class="PARAMETER">query</replaceable>
|
1999-07-06 19:16:42 +02:00
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
<refsect2 id="R2-SQL-CREATEVIEW-1">
|
2000-03-27 19:14:43 +02:00
|
|
|
<refsect2info>
|
|
|
|
<date>2000-03-25</date>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect2info>
|
|
|
|
<title>
|
1998-09-01 17:53:09 +02:00
|
|
|
Inputs
|
1999-07-06 19:16:42 +02:00
|
|
|
</title>
|
|
|
|
<para>
|
1999-07-22 17:09:15 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">view</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The name of a view to be created.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">query</replaceable></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>
|
1998-12-29 03:24:47 +01:00
|
|
|
</para>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect2>
|
|
|
|
|
|
|
|
<refsect2 id="R2-SQL-CREATEVIEW-2">
|
|
|
|
<refsect2info>
|
2000-03-27 19:14:43 +02:00
|
|
|
<date>2000-03-25</date>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect2info>
|
|
|
|
<title>
|
1998-09-01 17:53:09 +02:00
|
|
|
Outputs
|
1999-07-06 19:16:42 +02:00
|
|
|
</title>
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><computeroutput>
|
|
|
|
CREATE
|
|
|
|
</computeroutput></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The message returned if the view is successfully created.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><computeroutput>
|
|
|
|
ERROR: Relation '<replaceable class="parameter">view</replaceable>' already exists
|
|
|
|
</computeroutput></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This error occurs if the view specified already exists in the database.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><computeroutput>
|
|
|
|
NOTICE create: attribute named "<replaceable class="parameter">column</replaceable>" has an unknown type
|
|
|
|
</computeroutput></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
|
2000-03-27 19:14:43 +02:00
|
|
|
a warning:
|
1999-07-06 19:16:42 +02:00
|
|
|
<programlisting>
|
|
|
|
CREATE VIEW vista AS SELECT 'Hello World'
|
|
|
|
</programlisting>
|
2000-03-27 19:14:43 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
whereas this command does not:
|
2000-03-27 19:14:43 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<programlisting>
|
2000-03-27 19:14:43 +02:00
|
|
|
CREATE VIEW vista AS SELECT text 'Hello World'
|
1999-07-06 19:16:42 +02:00
|
|
|
</programlisting>
|
1998-12-29 03:24:47 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-07-06 19:16:42 +02:00
|
|
|
</variablelist>
|
1998-12-29 03:24:47 +01:00
|
|
|
</para>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect2>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1 id="R1-SQL-CREATEVIEW-1">
|
|
|
|
<refsect1info>
|
2000-03-27 19:14:43 +02:00
|
|
|
<date>2000-03-25</date>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect1info>
|
|
|
|
<title>
|
1998-09-01 17:53:09 +02:00
|
|
|
Description
|
1999-07-06 19:16:42 +02:00
|
|
|
</title>
|
|
|
|
<para>
|
1999-07-22 17:09:15 +02:00
|
|
|
<command>CREATE VIEW</command> will define a view of a table or
|
|
|
|
class. This view is not physically materialized. Specifically, a query
|
|
|
|
rewrite retrieve rule is automatically generated to support
|
|
|
|
retrieve operations on views.
|
1999-07-06 19:16:42 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<refsect2 id="R2-SQL-CREATEVIEW-3">
|
|
|
|
<refsect2info>
|
2000-03-27 19:14:43 +02:00
|
|
|
<date>2000-03-25</date>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect2info>
|
|
|
|
<title>
|
1998-09-01 17:53:09 +02:00
|
|
|
Notes
|
1999-07-06 19:16:42 +02:00
|
|
|
</title>
|
1999-07-22 17:09:15 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<para>
|
1999-07-22 17:09:15 +02:00
|
|
|
Currently, views are read only.
|
1999-07-06 19:16:42 +02:00
|
|
|
</para>
|
|
|
|
|
1998-09-01 17:53:09 +02:00
|
|
|
<para>
|
1999-07-22 17:09:15 +02:00
|
|
|
Use the <command>DROP VIEW</command> statement to drop views.
|
1998-09-01 17:53:09 +02:00
|
|
|
</para>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect2>
|
1998-12-29 03:24:47 +01:00
|
|
|
</refsect1>
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refsect1 id="R1-SQL-CREATEVIEW-2">
|
|
|
|
<title>
|
1998-09-01 17:53:09 +02:00
|
|
|
Usage
|
1999-07-06 19:16:42 +02:00
|
|
|
</title>
|
|
|
|
<para>
|
1998-09-01 17:53:09 +02:00
|
|
|
Create a view consisting of all Comedy films:
|
1999-07-06 19:16:42 +02:00
|
|
|
|
|
|
|
<programlisting>
|
1998-09-22 17:48:03 +02:00
|
|
|
CREATE VIEW kinds AS
|
|
|
|
SELECT *
|
|
|
|
FROM films
|
|
|
|
WHERE kind = 'Comedy';
|
1998-09-01 17:53:09 +02:00
|
|
|
|
1998-09-22 17:48:03 +02:00
|
|
|
SELECT * FROM kinds;
|
1998-09-01 17:53:09 +02:00
|
|
|
|
2000-03-26 20:32:30 +02:00
|
|
|
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
|
|
|
|
(2 rows)
|
1999-07-06 19:16:42 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
1998-09-01 17:53:09 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refsect1 id="R1-SQL-CREATEVIEW-3">
|
|
|
|
<title>
|
1998-09-01 17:53:09 +02:00
|
|
|
Compatibility
|
1999-07-06 19:16:42 +02:00
|
|
|
</title>
|
1998-09-01 17:53:09 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refsect2 id="R2-SQL-CREATEVIEW-5">
|
|
|
|
<refsect2info>
|
2000-03-27 19:14:43 +02:00
|
|
|
<date>2000-03-25</date>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsect2info>
|
|
|
|
<title>
|
1998-09-01 17:53:09 +02:00
|
|
|
SQL92
|
1999-07-06 19:16:42 +02:00
|
|
|
</title>
|
|
|
|
<para>
|
|
|
|
SQL92 specifies some additional capabilities for the
|
|
|
|
<command>CREATE VIEW</command> statement:
|
|
|
|
</para>
|
1998-09-22 17:48:03 +02:00
|
|
|
<synopsis>
|
|
|
|
CREATE VIEW <replaceable class="parameter">view</replaceable> [ <replaceable class="parameter">column</replaceable> [, ...] ]
|
1999-07-06 19:16:42 +02:00
|
|
|
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> ]
|
1998-09-22 17:48:03 +02:00
|
|
|
[ WITH [ CASCADE | LOCAL ] CHECK OPTION ]
|
|
|
|
</synopsis>
|
1998-09-01 17:53:09 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<para>
|
|
|
|
The optional clauses for the full SQL92 command are:
|
|
|
|
|
|
|
|
<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>
|
1999-07-22 17:09:15 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term>LOCAL</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Check for integrity on this view.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-07-22 17:09:15 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<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>
|
1998-09-01 17:53:09 +02:00
|
|
|
</refsect2>
|
|
|
|
</refsect1>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refentry>
|
1998-09-01 17:53:09 +02:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
1999-07-06 19:16:42 +02:00
|
|
|
sgml-omittag:nil
|
1998-09-01 17:53:09 +02:00
|
|
|
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:
|
1998-09-07 17:58:31 +02:00
|
|
|
-->
|