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

Commitf90dd28

Browse files
committed
Add ALTER DOMAIN ... RENAME
You could already rename domains using ALTER TYPE, but with this newcommand it is more consistent with how other commands treat domains asa subcategory of types.
1 parent8d15e3e commitf90dd28

File tree

7 files changed

+59
-4
lines changed

7 files changed

+59
-4
lines changed

‎doc/src/sgml/ref/alter_domain.sgml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
3535
VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable>
3636
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
3737
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
38+
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
39+
RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
3840
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
3941
SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
4042
</synopsis>
@@ -118,6 +120,15 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
118120
</listitem>
119121
</varlistentry>
120122

123+
<varlistentry>
124+
<term><literal>RENAME</literal></term>
125+
<listitem>
126+
<para>
127+
This form changes the name of the domain.
128+
</para>
129+
</listitem>
130+
</varlistentry>
131+
121132
<varlistentry>
122133
<term>SET SCHEMA</term>
123134
<listitem>
@@ -203,6 +214,15 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
203214
</listitem>
204215
</varlistentry>
205216

217+
<varlistentry>
218+
<term><replaceable class="PARAMETER">new_name</replaceable></term>
219+
<listitem>
220+
<para>
221+
The new name for the domain.
222+
</para>
223+
</listitem>
224+
</varlistentry>
225+
206226
<varlistentry>
207227
<term><replaceable class="PARAMETER">new_owner</replaceable></term>
208228
<listitem>
@@ -278,7 +298,7 @@ ALTER DOMAIN zipcode SET SCHEMA customers;
278298

279299
<para>
280300
<command>ALTER DOMAIN</command> conforms to the <acronym>SQL</acronym>
281-
standard, except for the <literal>OWNER</>, <literal>SET SCHEMA</> and
301+
standard, except for the <literal>OWNER</>, <literal>RENAME</literal>, <literal>SET SCHEMA</>, and
282302
<literal>VALIDATE CONSTRAINT</> variants, which are
283303
<productname>PostgreSQL</productname> extensions. The <literal>NOT VALID</>
284304
clause of the <literal>ADD CONSTRAINT</> variant is also a

‎src/backend/commands/alter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ ExecRenameStmt(RenameStmt *stmt)
134134
RenameTSConfiguration(stmt->object,stmt->newname);
135135
break;
136136

137+
caseOBJECT_DOMAIN:
137138
caseOBJECT_TYPE:
138-
RenameType(stmt->object,stmt->newname);
139+
RenameType(stmt);
139140
break;
140141

141142
default:

‎src/backend/commands/typecmds.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3074,8 +3074,10 @@ GetDomainConstraints(Oid typeOid)
30743074
* Execute ALTER TYPE RENAME
30753075
*/
30763076
void
3077-
RenameType(List*names,constchar*newTypeName)
3077+
RenameType(RenameStmt*stmt)
30783078
{
3079+
List*names=stmt->object;
3080+
constchar*newTypeName=stmt->newname;
30793081
TypeName*typename;
30803082
OidtypeOid;
30813083
Relationrel;
@@ -3099,6 +3101,13 @@ RenameType(List *names, const char *newTypeName)
30993101
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_TYPE,
31003102
format_type_be(typeOid));
31013103

3104+
/* ALTER DOMAIN used on a non-domain? */
3105+
if (stmt->renameType==OBJECT_DOMAIN&&typTup->typtype!=TYPTYPE_DOMAIN)
3106+
ereport(ERROR,
3107+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
3108+
errmsg("\"%s\" is not a domain",
3109+
format_type_be(typeOid))));
3110+
31023111
/*
31033112
* If it's a composite type, we need to check that it really is a
31043113
* free-standing composite type, and not a table's rowtype. We want people

‎src/backend/parser/gram.y

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6451,6 +6451,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
64516451
n->newname =$6;
64526452
$$ = (Node *)n;
64536453
}
6454+
|ALTERDOMAIN_Pany_nameRENAMETOname
6455+
{
6456+
RenameStmt *n = makeNode(RenameStmt);
6457+
n->renameType = OBJECT_DOMAIN;
6458+
n->object =$3;
6459+
n->newname =$6;
6460+
$$ = (Node *)n;
6461+
}
64546462
|ALTERFOREIGNDATA_PWRAPPERnameRENAMETOname
64556463
{
64566464
RenameStmt *n = makeNode(RenameStmt);

‎src/include/commands/typecmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern void AlterDomainDropConstraint(List *names, const char *constrName,
3737

3838
externList*GetDomainConstraints(OidtypeOid);
3939

40-
externvoidRenameType(List*names,constchar*newTypeName);
40+
externvoidRenameType(RenameStmt*stmt);
4141
externvoidAlterTypeOwner(List*names,OidnewOwnerId);
4242
externvoidAlterTypeOwnerInternal(OidtypeOid,OidnewOwnerId,
4343
boolhasDependEntry);

‎src/test/regress/expected/domain.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,10 @@ select array_elem_check(-1);
648648
ERROR: value for domain orderedpair violates check constraint "orderedpair_check"
649649
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
650650
drop function array_elem_check(int);
651+
--
652+
-- Renaming
653+
--
654+
create domain testdomain1 as int;
655+
alter domain testdomain1 rename to testdomain2;
656+
alter type testdomain2 rename to testdomain3; -- alter type also works
657+
drop domain testdomain3;

‎src/test/regress/sql/domain.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,13 @@ select array_elem_check(3);
483483
select array_elem_check(-1);
484484

485485
dropfunction array_elem_check(int);
486+
487+
488+
--
489+
-- Renaming
490+
--
491+
492+
createdomaintestdomain1asint;
493+
alterdomain testdomain1 rename to testdomain2;
494+
altertype testdomain2 rename to testdomain3;-- alter type also works
495+
dropdomain testdomain3;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp