<!entity alterTrigger system "alter_trigger.sgml">
<!entity alterType system "alter_type.sgml">
<!entity alterUser system "alter_user.sgml">
+<!entity alterView system "alter_view.sgml">
<!entity analyze system "analyze.sgml">
<!entity begin system "begin.sgml">
<!entity checkpoint system "checkpoint.sgml">
[ RESTART [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
[ OWNED BY { <replaceable class="parameter">table</replaceable>.<replaceable class="parameter">column</replaceable> | NONE } ]
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
+ALTER SEQUENCE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
</synopsis>
</refsynopsisdiv>
</listitem>
</varlistentry>
- <varlistentry>
- <term><replaceable class="parameter">new_schema</replaceable></term>
- <listitem>
- <para>
- The new schema for the sequence.
- </para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><replaceable class="parameter">new_schema</replaceable></term>
+ <listitem>
+ <para>
+ The new schema for the sequence.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="parameter">new_name</replaceable></term>
+ <listitem>
+ <para>
+ The new name for the sequence.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
</refsect1>
--- /dev/null
+<!--
+$PostgreSQL$
+PostgreSQL documentation
+-->
+
+<refentry id="SQL-ALTERVIEW">
+ <refmeta>
+ <refentrytitle id="SQL-ALTERVIEW-TITLE">ALTER VIEW</refentrytitle>
+ <refmiscinfo>SQL - Language Statements</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>ALTER VIEW</refname>
+ <refpurpose>change the definition of a view</refpurpose>
+ </refnamediv>
+
+ <indexterm zone="sql-alterview">
+ <primary>ALTER VIEW</primary>
+ </indexterm>
+
+ <refsynopsisdiv>
+<synopsis>
+ALTER VIEW <replaceable>name</replaceable> RENAME TO <replaceable>newname</replaceable>
+</synopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+
+ <para>
+ <command>ALTER VIEW</command> changes the definition of a
+ view. To execute this command you must be the owner of the view.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Parameters</title>
+
+ <variablelist>
+ <varlistentry>
+ <term><replaceable class="parameter">name</replaceable></term>
+ <listitem>
+ <para>
+ The name (optionally schema-qualified) of an existing view.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="parameter">newname</replaceable></term>
+ <listitem>
+ <para>
+ The new name of the view.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>Examples</title>
+
+ <para>
+ To rename the view <literal>foo</literal> to
+ <literal>bar</literal>:
+<programlisting>
+ALTER VIEW foo RENAME TO bar;
+</programlisting>
+ </para>
+
+ <refsect1>
+ <title>Compatibility</title>
+
+ <para>
+ <command>ALTER VIEW</command> is a <productname>PostgreSQL</>
+ extension of the SQL standard.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>See Also</title>
+
+ <simplelist type="inline">
+ <member><xref linkend="sql-createview" endterm="sql-createview-title"></member>
+ <member><xref linkend="sql-dropview" endterm="sql-dropview-title"></member>
+ </simplelist>
+ </refsect1>
+</refentry>
<title>See Also</title>
<simplelist type="inline">
+ <member><xref linkend="sql-alterview" endterm="sql-alterview-title"></member>
<member><xref linkend="sql-dropview" endterm="sql-dropview-title"></member>
</simplelist>
</refsect1>
<title>See Also</title>
<simplelist type="inline">
+ <member><xref linkend="sql-alterview" endterm="sql-alterview-title"></member>
<member><xref linkend="sql-createview" endterm="sql-createview-title"></member>
</simplelist>
</refsect1>
&alterTrigger;
&alterType;
&alterUser;
+ &alterView;
&analyze;
&begin;
&checkpoint;
break;
case OBJECT_TABLE:
+ case OBJECT_SEQUENCE:
+ case OBJECT_VIEW:
case OBJECT_INDEX:
case OBJECT_COLUMN:
case OBJECT_TRIGGER:
switch (stmt->renameType)
{
case OBJECT_TABLE:
+ case OBJECT_SEQUENCE:
+ case OBJECT_VIEW:
case OBJECT_INDEX:
{
/*
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
get_namespace_name(namespaceId));
- renamerel(relid, stmt->newname);
+ renamerel(relid, stmt->newname, stmt->renameType);
break;
}
case OBJECT_COLUMN:
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
+#include "nodes/parsenodes.h"
#include "optimizer/clauses.h"
#include "optimizer/plancat.h"
#include "optimizer/prep.h"
* sequence, AFAIK there's no need for it to be there.
*/
void
-renamerel(Oid myrelid, const char *newrelname)
+renamerel(Oid myrelid, const char *newrelname, ObjectType reltype)
{
Relation targetrelation;
Relation relrelation; /* for RELATION relation */
bool relhastriggers;
/*
- * Grab an exclusive lock on the target table or index, which we will NOT
- * release until end of transaction.
+ * Grab an exclusive lock on the target table, index, sequence or
+ * view, which we will NOT release until end of transaction.
*/
targetrelation = relation_open(myrelid, AccessExclusiveLock);
errmsg("permission denied: \"%s\" is a system catalog",
RelationGetRelationName(targetrelation))));
+ /*
+ * For compatibility with prior releases, we don't complain if
+ * ALTER TABLE or ALTER INDEX is used to rename a sequence or
+ * view.
+ */
relkind = targetrelation->rd_rel->relkind;
+ if (reltype == OBJECT_SEQUENCE && relkind != 'S')
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("\"%s\" is not a sequence",
+ RelationGetRelationName(targetrelation))));
+
+ if (reltype == OBJECT_VIEW && relkind != 'v')
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("\"%s\" is not a view",
+ RelationGetRelationName(targetrelation))));
+
relhastriggers = (targetrelation->rd_rel->reltriggers > 0);
/*
n->newname = $6;
$$ = (Node *)n;
}
+ | ALTER SEQUENCE relation_expr RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_SEQUENCE;
+ n->relation = $3;
+ n->subname = NULL;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
+ | ALTER VIEW relation_expr RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_VIEW;
+ n->relation = $3;
+ n->subname = NULL;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
| ALTER INDEX relation_expr RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
case OBJECT_SCHEMA:
tag = "ALTER SCHEMA";
break;
+ case OBJECT_SEQUENCE:
+ tag = "ALTER SEQUENCE";
+ break;
case OBJECT_COLUMN:
case OBJECT_TABLE:
tag = "ALTER TABLE";
case OBJECT_TRIGGER:
tag = "ALTER TRIGGER";
break;
+ case OBJECT_VIEW:
+ tag = "ALTER VIEW";
+ break;
default:
tag = "???";
break;
static const char *const list_ALTER[] =
{"AGGREGATE", "CONVERSION", "DATABASE", "DOMAIN", "FUNCTION",
"GROUP", "INDEX", "LANGUAGE", "OPERATOR", "ROLE", "SCHEMA", "SEQUENCE", "TABLE",
- "TABLESPACE", "TRIGGER", "TYPE", "USER", NULL};
+ "TABLESPACE", "TRIGGER", "TYPE", "USER", "VIEW", NULL};
COMPLETE_WITH_LIST(list_ALTER);
}
{
static const char *const list_ALTERSEQUENCE[] =
{"INCREMENT", "MINVALUE", "MAXVALUE", "RESTART", "NO", "CACHE", "CYCLE",
- "SET SCHEMA", NULL};
+ "SET SCHEMA", "RENAME TO", NULL};
COMPLETE_WITH_LIST(list_ALTERSEQUENCE);
}
COMPLETE_WITH_LIST(list_ALTERSEQUENCE2);
}
+ /* ALTER VIEW <name> */
+ else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
+ pg_strcasecmp(prev2_wd, "VIEW") == 0)
+ {
+ static const char *const list_ALTERVIEW[] = {"RENAME TO", NULL};
+
+ COMPLETE_WITH_LIST(list_ALTERVIEW);
+ }
/* ALTER TRIGGER <name>, add ON */
else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
bool recursing);
extern void renamerel(Oid myrelid,
- const char *newrelname);
+ const char *newrelname,
+ ObjectType reltype);
extern void find_composite_type_dependencies(Oid typeOid,
const char *origTblName,