mirror of
https://github.com/postgres/postgres.git
synced 2025-08-09 17:03:00 +03:00
Add CREATE RECURSIVE VIEW syntax
This is specified in the SQL standard. The CREATE RECURSIVE VIEW specification is transformed into a normal CREATE VIEW statement with a WITH RECURSIVE clause. reviewed by Abhijit Menon-Sen and Stephen Frost
This commit is contained in:
@@ -21,7 +21,7 @@ PostgreSQL documentation
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW <replaceable class="PARAMETER">name</replaceable> [ ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) ]
|
||||
CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] [ RECURSIVE ] VIEW <replaceable class="PARAMETER">name</replaceable> [ ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) ]
|
||||
[ WITH ( <replaceable class="PARAMETER">view_option_name</replaceable> [= <replaceable class="PARAMETER">view_option_value</replaceable>] [, ... ] ) ]
|
||||
AS <replaceable class="PARAMETER">query</replaceable>
|
||||
</synopsis>
|
||||
@@ -80,6 +80,23 @@ CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW <replaceable class="PARAMETER">n
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>RECURSIVE</></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Creates a recursive view. The syntax
|
||||
<synopsis>
|
||||
CREATE RECURSIVE VIEW <replaceable>name</> (<replaceable>columns</>) AS SELECT <replaceable>...</>;
|
||||
</synopsis>
|
||||
is equivalent to
|
||||
<synopsis>
|
||||
CREATE VIEW <replaceable>name</> AS WITH RECURSIVE <replaceable>name</> (<replaceable>columns</>) AS (SELECT <replaceable>...</>) SELECT <replaceable>columns</> FROM <replaceable>name</>;
|
||||
</synopsis>
|
||||
A view column list must be specified for a recursive view.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">name</replaceable></term>
|
||||
<listitem>
|
||||
@@ -282,6 +299,16 @@ CREATE VIEW comedies AS
|
||||
<literal>*</> was used to create the view, columns added later to
|
||||
the table will not be part of the view.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Create a recursive view consisting of the numbers from 1 to 100:
|
||||
<programlisting>
|
||||
CREATE RECURSIVE VIEW nums_1_100 (n) AS
|
||||
VALUES (1)
|
||||
UNION ALL
|
||||
SELECT n+1 FROM nums_1_100 WHERE n < 100;
|
||||
</programlisting>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
Reference in New Issue
Block a user