Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita558981

Browse files
author
Neil Conway
committed
Add ALTER VIEW ... RENAME TO, and a RENAME TO clause to ALTER SEQUENCE.
Sequences and views could previously be renamed using ALTER TABLE, butthis was a repeated source of confusion for users. Update the docs,and psql tab completion. Patch from David Fetter; various minor fixesby myself.
1 parenta1587e4 commita558981

File tree

12 files changed

+184
-26
lines changed

12 files changed

+184
-26
lines changed

‎doc/src/sgml/ref/allfiles.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.70 2007/04/26 16:13:08 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.71 2007/07/03 01:30:35 neilc Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -25,6 +25,7 @@ Complete list of usable sgml source files in this directory.
2525
<!entity alterTrigger system "alter_trigger.sgml">
2626
<!entity alterType system "alter_type.sgml">
2727
<!entity alterUser system "alter_user.sgml">
28+
<!entity alterView system "alter_view.sgml">
2829
<!entity analyze system "analyze.sgml">
2930
<!entity begin system "begin.sgml">
3031
<!entity checkpoint system "checkpoint.sgml">

‎doc/src/sgml/ref/alter_sequence.sgml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.16 2007/01/31 23:26:02 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.17 2007/07/03 01:30:35 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -29,6 +29,7 @@ ALTER SEQUENCE <replaceable class="parameter">name</replaceable> [ INCREMENT [ B
2929
[ RESTART [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
3030
[ OWNED BY { <replaceable class="parameter">table</replaceable>.<replaceable class="parameter">column</replaceable> | NONE } ]
3131
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
32+
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
3233
</synopsis>
3334
</refsynopsisdiv>
3435

@@ -182,14 +183,24 @@ ALTER SEQUENCE <replaceable class="parameter">name</replaceable> SET SCHEMA <rep
182183
</listitem>
183184
</varlistentry>
184185

185-
<varlistentry>
186-
<term><replaceable class="parameter">new_schema</replaceable></term>
187-
<listitem>
188-
<para>
189-
The new schema for the sequence.
190-
</para>
191-
</listitem>
192-
</varlistentry>
186+
<varlistentry>
187+
<term><replaceable class="parameter">new_schema</replaceable></term>
188+
<listitem>
189+
<para>
190+
The new schema for the sequence.
191+
</para>
192+
</listitem>
193+
</varlistentry>
194+
195+
<varlistentry>
196+
<term><replaceable class="parameter">new_name</replaceable></term>
197+
<listitem>
198+
<para>
199+
The new name for the sequence.
200+
</para>
201+
</listitem>
202+
</varlistentry>
203+
193204
</variablelist>
194205
</para>
195206
</refsect1>

‎doc/src/sgml/ref/alter_view.sgml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!--
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_view.sgml,v 1.1 2007/07/03 01:30:35 neilc Exp $
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-ALTERVIEW">
7+
<refmeta>
8+
<refentrytitle id="SQL-ALTERVIEW-TITLE">ALTER VIEW</refentrytitle>
9+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
10+
</refmeta>
11+
12+
<refnamediv>
13+
<refname>ALTER VIEW</refname>
14+
<refpurpose>change the definition of a view</refpurpose>
15+
</refnamediv>
16+
17+
<indexterm zone="sql-alterview">
18+
<primary>ALTER VIEW</primary>
19+
</indexterm>
20+
21+
<refsynopsisdiv>
22+
<synopsis>
23+
ALTER VIEW <replaceable>name</replaceable> RENAME TO <replaceable>newname</replaceable>
24+
</synopsis>
25+
</refsynopsisdiv>
26+
27+
<refsect1>
28+
<title>Description</title>
29+
30+
<para>
31+
<command>ALTER VIEW</command> changes the definition of a
32+
view. To execute this command you must be the owner of the view.
33+
</para>
34+
</refsect1>
35+
36+
<refsect1>
37+
<title>Parameters</title>
38+
39+
<variablelist>
40+
<varlistentry>
41+
<term><replaceable class="parameter">name</replaceable></term>
42+
<listitem>
43+
<para>
44+
The name (optionally schema-qualified) of an existing view.
45+
</para>
46+
</listitem>
47+
</varlistentry>
48+
49+
<varlistentry>
50+
<term><replaceable class="parameter">newname</replaceable></term>
51+
<listitem>
52+
<para>
53+
The new name of the view.
54+
</para>
55+
</listitem>
56+
</varlistentry>
57+
</variablelist>
58+
</refsect1>
59+
60+
<refsect1>
61+
<title>Examples</title>
62+
63+
<para>
64+
To rename the view <literal>foo</literal> to
65+
<literal>bar</literal>:
66+
<programlisting>
67+
ALTER VIEW foo RENAME TO bar;
68+
</programlisting>
69+
</para>
70+
71+
<refsect1>
72+
<title>Compatibility</title>
73+
74+
<para>
75+
<command>ALTER VIEW</command> is a <productname>PostgreSQL</>
76+
extension of the SQL standard.
77+
</para>
78+
</refsect1>
79+
80+
<refsect1>
81+
<title>See Also</title>
82+
83+
<simplelist type="inline">
84+
<member><xref linkend="sql-createview" endterm="sql-createview-title"></member>
85+
<member><xref linkend="sql-dropview" endterm="sql-dropview-title"></member>
86+
</simplelist>
87+
</refsect1>
88+
</refentry>

‎doc/src/sgml/ref/create_view.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_view.sgml,v 1.35 2007/02/01 00:28:18 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_view.sgml,v 1.36 2007/07/03 01:30:35 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -226,6 +226,7 @@ CREATE VIEW <replaceable class="parameter">name</replaceable> [ ( <replaceable c
226226
<title>See Also</title>
227227

228228
<simplelist type="inline">
229+
<member><xref linkend="sql-alterview" endterm="sql-alterview-title"></member>
229230
<member><xref linkend="sql-dropview" endterm="sql-dropview-title"></member>
230231
</simplelist>
231232
</refsect1>

‎doc/src/sgml/ref/drop_view.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_view.sgml,v 1.23 2006/09/16 00:30:18 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_view.sgml,v 1.24 2007/07/03 01:30:35 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -104,6 +104,7 @@ DROP VIEW kinds;
104104
<title>See Also</title>
105105

106106
<simplelist type="inline">
107+
<member><xref linkend="sql-alterview" endterm="sql-alterview-title"></member>
107108
<member><xref linkend="sql-createview" endterm="sql-createview-title"></member>
108109
</simplelist>
109110
</refsect1>

‎doc/src/sgml/reference.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/reference.sgml,v 1.63 2007/04/26 16:13:08 neilc Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/reference.sgml,v 1.64 2007/07/03 01:30:35 neilc Exp $ -->
22

33
<part id="reference">
44
<title>Reference</title>
@@ -53,6 +53,7 @@
5353
&alterTrigger;
5454
&alterType;
5555
&alterUser;
56+
&alterView;
5657
&analyze;
5758
&begin;
5859
&checkpoint;

‎src/backend/commands/alter.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.23 2007/03/26 16:58:38 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.24 2007/07/03 01:30:36 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -83,6 +83,8 @@ ExecRenameStmt(RenameStmt *stmt)
8383
break;
8484

8585
caseOBJECT_TABLE:
86+
caseOBJECT_SEQUENCE:
87+
caseOBJECT_VIEW:
8688
caseOBJECT_INDEX:
8789
caseOBJECT_COLUMN:
8890
caseOBJECT_TRIGGER:
@@ -96,6 +98,8 @@ ExecRenameStmt(RenameStmt *stmt)
9698
switch (stmt->renameType)
9799
{
98100
caseOBJECT_TABLE:
101+
caseOBJECT_SEQUENCE:
102+
caseOBJECT_VIEW:
99103
caseOBJECT_INDEX:
100104
{
101105
/*
@@ -113,7 +117,7 @@ ExecRenameStmt(RenameStmt *stmt)
113117
aclcheck_error(aclresult,ACL_KIND_NAMESPACE,
114118
get_namespace_name(namespaceId));
115119

116-
renamerel(relid,stmt->newname);
120+
renamerel(relid,stmt->newname,stmt->renameType);
117121
break;
118122
}
119123
caseOBJECT_COLUMN:

‎src/backend/commands/tablecmds.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.228 2007/06/23 22:12:50 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.229 2007/07/03 01:30:36 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -41,6 +41,7 @@
4141
#include"executor/executor.h"
4242
#include"miscadmin.h"
4343
#include"nodes/makefuncs.h"
44+
#include"nodes/parsenodes.h"
4445
#include"optimizer/clauses.h"
4546
#include"optimizer/plancat.h"
4647
#include"optimizer/prep.h"
@@ -1621,7 +1622,7 @@ renameatt(Oid myrelid,
16211622
* sequence, AFAIK there's no need for it to be there.
16221623
*/
16231624
void
1624-
renamerel(Oidmyrelid,constchar*newrelname)
1625+
renamerel(Oidmyrelid,constchar*newrelname,ObjectTypereltype)
16251626
{
16261627
Relationtargetrelation;
16271628
Relationrelrelation;/* for RELATION relation */
@@ -1633,8 +1634,8 @@ renamerel(Oid myrelid, const char *newrelname)
16331634
boolrelhastriggers;
16341635

16351636
/*
1636-
* Grab an exclusive lock on the target table orindex,which we will NOT
1637-
* release until end of transaction.
1637+
* Grab an exclusive lock on the target table,index,sequence or
1638+
*view, which we will NOTrelease until end of transaction.
16381639
*/
16391640
targetrelation=relation_open(myrelid,AccessExclusiveLock);
16401641

@@ -1647,7 +1648,24 @@ renamerel(Oid myrelid, const char *newrelname)
16471648
errmsg("permission denied: \"%s\" is a system catalog",
16481649
RelationGetRelationName(targetrelation))));
16491650

1651+
/*
1652+
* For compatibility with prior releases, we don't complain if
1653+
* ALTER TABLE or ALTER INDEX is used to rename a sequence or
1654+
* view.
1655+
*/
16501656
relkind=targetrelation->rd_rel->relkind;
1657+
if (reltype==OBJECT_SEQUENCE&&relkind!='S')
1658+
ereport(ERROR,
1659+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1660+
errmsg("\"%s\" is not a sequence",
1661+
RelationGetRelationName(targetrelation))));
1662+
1663+
if (reltype==OBJECT_VIEW&&relkind!='v')
1664+
ereport(ERROR,
1665+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1666+
errmsg("\"%s\" is not a view",
1667+
RelationGetRelationName(targetrelation))));
1668+
16511669
relhastriggers= (targetrelation->rd_rel->reltriggers>0);
16521670

16531671
/*

‎src/backend/parser/gram.y

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.596 2007/06/23 22:12:51 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.597 2007/07/03 01:30:36 neilc Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -4546,6 +4546,24 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
45464546
n->newname =$6;
45474547
$$ = (Node *)n;
45484548
}
4549+
| ALTER SEQUENCE relation_expr RENAME TO name
4550+
{
4551+
RenameStmt *n = makeNode(RenameStmt);
4552+
n->renameType = OBJECT_SEQUENCE;
4553+
n->relation =$3;
4554+
n->subname =NULL;
4555+
n->newname =$6;
4556+
$$ = (Node *)n;
4557+
}
4558+
| ALTER VIEW relation_expr RENAME TO name
4559+
{
4560+
RenameStmt *n = makeNode(RenameStmt);
4561+
n->renameType = OBJECT_VIEW;
4562+
n->relation =$3;
4563+
n->subname =NULL;
4564+
n->newname =$6;
4565+
$$ = (Node *)n;
4566+
}
45494567
| ALTER INDEX relation_expr RENAME TO name
45504568
{
45514569
RenameStmt *n = makeNode(RenameStmt);

‎src/backend/tcop/utility.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.282 2007/06/28 00:02:39 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.283 2007/07/03 01:30:37 neilc Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -1574,6 +1574,9 @@ CreateCommandTag(Node *parsetree)
15741574
caseOBJECT_SCHEMA:
15751575
tag="ALTER SCHEMA";
15761576
break;
1577+
caseOBJECT_SEQUENCE:
1578+
tag="ALTER SEQUENCE";
1579+
break;
15771580
caseOBJECT_COLUMN:
15781581
caseOBJECT_TABLE:
15791582
tag="ALTER TABLE";
@@ -1584,6 +1587,9 @@ CreateCommandTag(Node *parsetree)
15841587
caseOBJECT_TRIGGER:
15851588
tag="ALTER TRIGGER";
15861589
break;
1590+
caseOBJECT_VIEW:
1591+
tag="ALTER VIEW";
1592+
break;
15871593
default:
15881594
tag="???";
15891595
break;

‎src/bin/psql/tab-complete.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.165 2007/06/13 23:59:47 neilc Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.166 2007/07/03 01:30:37 neilc Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -602,7 +602,7 @@ psql_completion(char *text, int start, int end)
602602
staticconstchar*constlist_ALTER[]=
603603
{"AGGREGATE","CONVERSION","DATABASE","DOMAIN","FUNCTION",
604604
"GROUP","INDEX","LANGUAGE","OPERATOR","ROLE","SCHEMA","SEQUENCE","TABLE",
605-
"TABLESPACE","TRIGGER","TYPE","USER",NULL};
605+
"TABLESPACE","TRIGGER","TYPE","USER","VIEW",NULL};
606606

607607
COMPLETE_WITH_LIST(list_ALTER);
608608
}
@@ -714,7 +714,7 @@ psql_completion(char *text, int start, int end)
714714
{
715715
staticconstchar*constlist_ALTERSEQUENCE[]=
716716
{"INCREMENT","MINVALUE","MAXVALUE","RESTART","NO","CACHE","CYCLE",
717-
"SET SCHEMA",NULL};
717+
"SET SCHEMA","RENAME TO",NULL};
718718

719719
COMPLETE_WITH_LIST(list_ALTERSEQUENCE);
720720
}
@@ -728,6 +728,14 @@ psql_completion(char *text, int start, int end)
728728

729729
COMPLETE_WITH_LIST(list_ALTERSEQUENCE2);
730730
}
731+
/* ALTER VIEW <name> */
732+
elseif (pg_strcasecmp(prev3_wd,"ALTER")==0&&
733+
pg_strcasecmp(prev2_wd,"VIEW")==0)
734+
{
735+
staticconstchar*constlist_ALTERVIEW[]= {"RENAME TO",NULL};
736+
737+
COMPLETE_WITH_LIST(list_ALTERVIEW);
738+
}
731739
/* ALTER TRIGGER <name>, add ON */
732740
elseif (pg_strcasecmp(prev3_wd,"ALTER")==0&&
733741
pg_strcasecmp(prev2_wd,"TRIGGER")==0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp