ok

Mini Shell

Direktori : /opt/alt/postgresql11/usr/share/man/man7/
Upload File :
Current File : //opt/alt/postgresql11/usr/share/man/man7/CREATE_VIEW.7

'\" t
.\"     Title: CREATE VIEW
.\"    Author: The PostgreSQL Global Development Group
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\"      Date: 2017-11-06
.\"    Manual: PostgreSQL 9.2.24 Documentation
.\"    Source: PostgreSQL 9.2.24
.\"  Language: English
.\"
.TH "CREATE VIEW" "7" "2017-11-06" "PostgreSQL 9.2.24" "PostgreSQL 9.2.24 Documentation"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
CREATE_VIEW \- define a new view
.\" CREATE VIEW
.SH "SYNOPSIS"
.sp
.nf
CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW \fIname\fR [ ( \fIcolumn_name\fR [, \&.\&.\&.] ) ]
    [ WITH ( \fIview_option_name\fR [= \fIview_option_value\fR] [, \&.\&.\&. ] ) ]
    AS \fIquery\fR
.fi
.SH "DESCRIPTION"
.PP
\fBCREATE VIEW\fR
defines a view of a query\&. The view is not physically materialized\&. Instead, the query is run every time the view is referenced in a query\&.
.PP
\fBCREATE OR REPLACE VIEW\fR
is similar, but if a view of the same name already exists, it is replaced\&. The new query must generate the same columns that were generated by the existing view query (that is, the same column names in the same order and with the same data types), but it may add additional columns to the end of the list\&. The calculations giving rise to the output columns may be completely different\&.
.PP
If a schema name is given (for example,
CREATE VIEW myschema\&.myview \&.\&.\&.) then the view is created in the specified schema\&. Otherwise it is created in the current schema\&. Temporary views exist in a special schema, so a schema name cannot be given when creating a temporary view\&. The name of the view must be distinct from the name of any other view, table, sequence, index or foreign table in the same schema\&.
.SH "PARAMETERS"
.PP
TEMPORARY or TEMP
.RS 4
If specified, the view is created as a temporary view\&. Temporary views are automatically dropped at the end of the current session\&. Existing permanent relations with the same name are not visible to the current session while the temporary view exists, unless they are referenced with schema\-qualified names\&.
.sp
If any of the tables referenced by the view are temporary, the view is created as a temporary view (whether
TEMPORARY
is specified or not)\&.
.RE
.PP
\fIname\fR
.RS 4
The name (optionally schema\-qualified) of a view to be created\&.
.RE
.PP
\fIcolumn_name\fR
.RS 4
An optional list of names to be used for columns of the view\&. If not given, the column names are deduced from the query\&.
.RE
.PP
WITH ( \fIview_option_name\fR [= \fIview_option_value\fR] [, \&.\&.\&. ] )
.RS 4
This clause specifies optional parameters for a view; currently, the only supported parameter name is
security_barrier, which should be enabled when a view is intended to provide row\-level security\&. See
Section 37.4, \(lqRules and Privileges\(rq, in the documentation
for full details\&.
.RE
.PP
\fIquery\fR
.RS 4
A
\fBSELECT\fR(7)
or
\fBVALUES\fR(7)
command which will provide the columns and rows of the view\&.
.RE
.SH "NOTES"
.PP
Currently, views are read only: the system will not allow an insert, update, or delete on a view\&. You can get the effect of an updatable view by creating
INSTEAD
triggers on the view, which must convert attempted inserts, etc\&. on the view into appropriate actions on other tables\&. For more information see
CREATE TRIGGER (\fBCREATE_TRIGGER\fR(7))\&. Another possibility is to create rules (see
CREATE RULE (\fBCREATE_RULE\fR(7))), but in practice triggers are easier to understand and use correctly\&.
.PP
Use the
DROP VIEW (\fBDROP_VIEW\fR(7))
statement to drop views\&.
.PP
Be careful that the names and types of the view\*(Aqs columns will be assigned the way you want\&. For example:
.sp
.if n \{\
.RS 4
.\}
.nf
CREATE VIEW vista AS SELECT \*(AqHello World\*(Aq;
.fi
.if n \{\
.RE
.\}
.sp
is bad form in two ways: the column name defaults to
?column?, and the column data type defaults to
unknown\&. If you want a string literal in a view\*(Aqs result, use something like:
.sp
.if n \{\
.RS 4
.\}
.nf
CREATE VIEW vista AS SELECT text \*(AqHello World\*(Aq AS hello;
.fi
.if n \{\
.RE
.\}
.PP
Access to tables referenced in the view is determined by permissions of the view owner\&. In some cases, this can be used to provide secure but restricted access to the underlying tables\&. However, not all views are secure against tampering; see
Section 37.4, \(lqRules and Privileges\(rq, in the documentation
for details\&. Functions called in the view are treated the same as if they had been called directly from the query using the view\&. Therefore the user of a view must have permissions to call all functions used by the view\&.
.PP
When
\fBCREATE OR REPLACE VIEW\fR
is used on an existing view, only the view\*(Aqs defining SELECT rule is changed\&. Other view properties, including ownership, permissions, and non\-SELECT rules, remain unchanged\&. You must own the view to replace it (this includes being a member of the owning role)\&.
.SH "EXAMPLES"
.PP
Create a view consisting of all comedy films:
.sp
.if n \{\
.RS 4
.\}
.nf
CREATE VIEW comedies AS
    SELECT *
    FROM films
    WHERE kind = \*(AqComedy\*(Aq;
.fi
.if n \{\
.RE
.\}
.sp
This will create a view containing the columns that are in the
film
table at the time of view creation\&. Though
*
was used to create the view, columns added later to the table will not be part of the view\&.
.SH "COMPATIBILITY"
.PP
The SQL standard specifies some additional capabilities for the
\fBCREATE VIEW\fR
statement:
.sp
.if n \{\
.RS 4
.\}
.nf
CREATE VIEW \fIname\fR [ ( \fIcolumn_name\fR [, \&.\&.\&.] ) ]
    AS \fIquery\fR
    [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
.fi
.if n \{\
.RE
.\}
.PP
The optional clauses for the full SQL command are:
.PP
CHECK OPTION
.RS 4
This option has to do with updatable views\&. All
\fBINSERT\fR
and
\fBUPDATE\fR
commands on the view will be checked to ensure data satisfy the view\-defining condition (that is, the new data would be visible through the view)\&. If they do not, the update will be rejected\&.
.RE
.PP
LOCAL
.RS 4
Check for integrity on this view\&.
.RE
.PP
CASCADED
.RS 4
Check for integrity on this view and on any dependent view\&.
CASCADED
is assumed if neither
CASCADED
nor
LOCAL
is specified\&.
.RE
.PP
\fBCREATE OR REPLACE VIEW\fR
is a
PostgreSQL
language extension\&. So is the concept of a temporary view\&.
.SH "SEE ALSO"
ALTER VIEW (\fBALTER_VIEW\fR(7)), DROP VIEW (\fBDROP_VIEW\fR(7))

Zerion Mini Shell 1.0