1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-21 05:21:08 +03:00

Rearrange ALTER TABLE syntax processing as per my recent proposal: the

grammar allows ALTER TABLE/INDEX/SEQUENCE/VIEW interchangeably for all
subforms of those commands, and then we sort out what's really legal
at execution time.  This allows the ALTER SEQUENCE/VIEW reference pages
to fully document all the ALTER forms available for sequences and views
respectively, and eliminates a longstanding cause of confusion for users.

The net effect is that the following forms are allowed that weren't before:
	ALTER SEQUENCE OWNER TO
	ALTER VIEW ALTER COLUMN SET/DROP DEFAULT
	ALTER VIEW OWNER TO
	ALTER VIEW SET SCHEMA
(There's no actual functionality gain here, but formerly you had to say
ALTER TABLE instead.)

Interestingly, the grammar tables actually get smaller, probably because
there are fewer special cases to keep track of.

I did not disallow using ALTER TABLE for these operations.  Perhaps we
should, but there's a backwards-compatibility issue if we do; in fact
it would break existing pg_dump scripts.  I did however tighten up
ALTER SEQUENCE and ALTER VIEW to reject non-sequences and non-views
in the new cases as well as a couple of cases where they didn't before.

The patch doesn't change pg_dump to use the new syntaxes, either.
This commit is contained in:
Tom Lane
2008-06-15 01:25:54 +00:00
parent bd2ef8707f
commit a0b012a1ab
7 changed files with 235 additions and 81 deletions

View File

@@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_view.sgml,v 1.3 2007/10/03 16:48:43 tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_view.sgml,v 1.4 2008/06/15 01:25:53 tgl Exp $
PostgreSQL documentation
-->
@@ -20,7 +20,11 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
ALTER VIEW <replaceable>name</replaceable> RENAME TO <replaceable>newname</replaceable>
ALTER VIEW <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET DEFAULT <replaceable class="PARAMETER">expression</replaceable>
ALTER VIEW <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> DROP DEFAULT
ALTER VIEW <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
ALTER VIEW <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
ALTER VIEW <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
</synopsis>
</refsynopsisdiv>
@@ -28,9 +32,20 @@ ALTER VIEW <replaceable>name</replaceable> RENAME TO <replaceable>newname</repla
<title>Description</title>
<para>
<command>ALTER VIEW</command> changes the definition of a view.
The only currently available functionality is to rename the view.
To execute this command you must be the owner of the view.
<command>ALTER VIEW</command> changes various auxiliary properties
of a view. (If you want to modify the view's defining query,
use <command>CREATE OR REPLACE VIEW</>.)
</para>
<para>
You must own the view to use <command>ALTER VIEW</>.
To change a view's schema, you must also have <literal>CREATE</>
privilege on the new schema.
To alter the owner, you must also be a direct or indirect member of the new
owning role, and that role must have <literal>CREATE</literal> privilege on
the view's schema. (These restrictions enforce that altering the owner
doesn't do anything you couldn't do by dropping and recreating the view.
However, a superuser can alter ownership of any view anyway.)
</para>
</refsect1>
@@ -48,10 +63,41 @@ ALTER VIEW <replaceable>name</replaceable> RENAME TO <replaceable>newname</repla
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">newname</replaceable></term>
<term><literal>SET</literal>/<literal>DROP DEFAULT</literal></term>
<listitem>
<para>
The new name of the view.
These forms set or remove the default value for a column.
A default value associated with a view column is
inserted into <command>INSERT</> statements on the view before
the view's <literal>ON INSERT</literal> rule is applied, if
the <command>INSERT</> does not specify a value for the column.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">new_owner</replaceable></term>
<listitem>
<para>
The user name of the new owner of the view.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">new_name</replaceable></term>
<listitem>
<para>
The new name for the view.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">new_schema</replaceable></term>
<listitem>
<para>
The new schema for the view.
</para>
</listitem>
</varlistentry>
@@ -62,11 +108,9 @@ ALTER VIEW <replaceable>name</replaceable> RENAME TO <replaceable>newname</repla
<title>Notes</title>
<para>
Some variants of <command>ALTER TABLE</command> can be used with
views as well; for example, to rename a view it is also
possible to use <command>ALTER TABLE RENAME</command>. To change
the schema or owner of a view, you currently must use <command>ALTER
TABLE</>.
For historical reasons, <command>ALTER TABLE</command> can be used with
views too; but the only variants of <command>ALTER TABLE</command>
that are allowed with views are equivalent to the ones shown above.
</para>
</refsect1>