Commit f90dd280 authored by Peter Eisentraut's avatar Peter Eisentraut

Add ALTER DOMAIN ... RENAME

You could already rename domains using ALTER TYPE, but with this new
command it is more consistent with how other commands treat domains as
a subcategory of types.
parent 8d15e3ec
...@@ -35,6 +35,8 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ...@@ -35,6 +35,8 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
</synopsis> </synopsis>
...@@ -118,6 +120,15 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ...@@ -118,6 +120,15 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><literal>RENAME</literal></term>
<listitem>
<para>
This form changes the name of the domain.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>SET SCHEMA</term> <term>SET SCHEMA</term>
<listitem> <listitem>
...@@ -203,6 +214,15 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ...@@ -203,6 +214,15 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">new_name</replaceable></term>
<listitem>
<para>
The new name for the domain.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><replaceable class="PARAMETER">new_owner</replaceable></term> <term><replaceable class="PARAMETER">new_owner</replaceable></term>
<listitem> <listitem>
...@@ -278,7 +298,7 @@ ALTER DOMAIN zipcode SET SCHEMA customers; ...@@ -278,7 +298,7 @@ ALTER DOMAIN zipcode SET SCHEMA customers;
<para> <para>
<command>ALTER DOMAIN</command> conforms to the <acronym>SQL</acronym> <command>ALTER DOMAIN</command> conforms to the <acronym>SQL</acronym>
standard, except for the <literal>OWNER</>, <literal>SET SCHEMA</> and standard, except for the <literal>OWNER</>, <literal>RENAME</literal>, <literal>SET SCHEMA</>, and
<literal>VALIDATE CONSTRAINT</> variants, which are <literal>VALIDATE CONSTRAINT</> variants, which are
<productname>PostgreSQL</productname> extensions. The <literal>NOT VALID</> <productname>PostgreSQL</productname> extensions. The <literal>NOT VALID</>
clause of the <literal>ADD CONSTRAINT</> variant is also a clause of the <literal>ADD CONSTRAINT</> variant is also a
......
...@@ -134,8 +134,9 @@ ExecRenameStmt(RenameStmt *stmt) ...@@ -134,8 +134,9 @@ ExecRenameStmt(RenameStmt *stmt)
RenameTSConfiguration(stmt->object, stmt->newname); RenameTSConfiguration(stmt->object, stmt->newname);
break; break;
case OBJECT_DOMAIN:
case OBJECT_TYPE: case OBJECT_TYPE:
RenameType(stmt->object, stmt->newname); RenameType(stmt);
break; break;
default: default:
......
...@@ -3074,8 +3074,10 @@ GetDomainConstraints(Oid typeOid) ...@@ -3074,8 +3074,10 @@ GetDomainConstraints(Oid typeOid)
* Execute ALTER TYPE RENAME * Execute ALTER TYPE RENAME
*/ */
void void
RenameType(List *names, const char *newTypeName) RenameType(RenameStmt *stmt)
{ {
List *names = stmt->object;
const char *newTypeName = stmt->newname;
TypeName *typename; TypeName *typename;
Oid typeOid; Oid typeOid;
Relation rel; Relation rel;
...@@ -3099,6 +3101,13 @@ RenameType(List *names, const char *newTypeName) ...@@ -3099,6 +3101,13 @@ RenameType(List *names, const char *newTypeName)
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
format_type_be(typeOid)); format_type_be(typeOid));
/* ALTER DOMAIN used on a non-domain? */
if (stmt->renameType == OBJECT_DOMAIN && typTup->typtype != TYPTYPE_DOMAIN)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a domain",
format_type_be(typeOid))));
/* /*
* If it's a composite type, we need to check that it really is a * If it's a composite type, we need to check that it really is a
* free-standing composite type, and not a table's rowtype. We want people * free-standing composite type, and not a table's rowtype. We want people
......
...@@ -6451,6 +6451,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name ...@@ -6451,6 +6451,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
n->newname = $6; n->newname = $6;
$$ = (Node *)n; $$ = (Node *)n;
} }
| ALTER DOMAIN_P any_name RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
n->renameType = OBJECT_DOMAIN;
n->object = $3;
n->newname = $6;
$$ = (Node *)n;
}
| ALTER FOREIGN DATA_P WRAPPER name RENAME TO name | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
{ {
RenameStmt *n = makeNode(RenameStmt); RenameStmt *n = makeNode(RenameStmt);
......
...@@ -37,7 +37,7 @@ extern void AlterDomainDropConstraint(List *names, const char *constrName, ...@@ -37,7 +37,7 @@ extern void AlterDomainDropConstraint(List *names, const char *constrName,
extern List *GetDomainConstraints(Oid typeOid); extern List *GetDomainConstraints(Oid typeOid);
extern void RenameType(List *names, const char *newTypeName); extern void RenameType(RenameStmt *stmt);
extern void AlterTypeOwner(List *names, Oid newOwnerId); extern void AlterTypeOwner(List *names, Oid newOwnerId);
extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId, extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
bool hasDependEntry); bool hasDependEntry);
......
...@@ -648,3 +648,10 @@ select array_elem_check(-1); ...@@ -648,3 +648,10 @@ select array_elem_check(-1);
ERROR: value for domain orderedpair violates check constraint "orderedpair_check" ERROR: value for domain orderedpair violates check constraint "orderedpair_check"
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
drop function array_elem_check(int); drop function array_elem_check(int);
--
-- Renaming
--
create domain testdomain1 as int;
alter domain testdomain1 rename to testdomain2;
alter type testdomain2 rename to testdomain3; -- alter type also works
drop domain testdomain3;
...@@ -483,3 +483,13 @@ select array_elem_check(3); ...@@ -483,3 +483,13 @@ select array_elem_check(3);
select array_elem_check(-1); select array_elem_check(-1);
drop function array_elem_check(int); drop function array_elem_check(int);
--
-- Renaming
--
create domain testdomain1 as int;
alter domain testdomain1 rename to testdomain2;
alter type testdomain2 rename to testdomain3; -- alter type also works
drop domain testdomain3;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment