VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</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>
SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
</synopsis>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><literal>RENAME</literal></term>
+ <listitem>
+ <para>
+ This form changes the name of the domain.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term>SET SCHEMA</term>
<listitem>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><replaceable class="PARAMETER">new_name</replaceable></term>
+ <listitem>
+ <para>
+ The new name for the domain.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><replaceable class="PARAMETER">new_owner</replaceable></term>
<listitem>
<para>
<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
<productname>PostgreSQL</productname> extensions. The <literal>NOT VALID</>
clause of the <literal>ADD CONSTRAINT</> variant is also a
RenameTSConfiguration(stmt->object, stmt->newname);
break;
+ case OBJECT_DOMAIN:
case OBJECT_TYPE:
- RenameType(stmt->object, stmt->newname);
+ RenameType(stmt);
break;
default:
* Execute ALTER TYPE RENAME
*/
void
-RenameType(List *names, const char *newTypeName)
+RenameType(RenameStmt *stmt)
{
+ List *names = stmt->object;
+ const char *newTypeName = stmt->newname;
TypeName *typename;
Oid typeOid;
Relation rel;
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
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
* free-standing composite type, and not a table's rowtype. We want people
n->newname = $6;
$$ = (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
{
RenameStmt *n = makeNode(RenameStmt);
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 AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
bool hasDependEntry);
ERROR: value for domain orderedpair violates check constraint "orderedpair_check"
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
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;
select array_elem_check(-1);
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;