editorialization.
-ALTER AGGREGATE name ( type ) RENAME TO newname
-ALTER AGGREGATE name ( type ) OWNER TO newowner
+ALTER AGGREGATE name ( type ) RENAME TO new_name
+ALTER AGGREGATE name ( type ) OWNER TO new_owner
+ALTER AGGREGATE name ( type ) SET SCHEMA new_schema
ALTER AGGREGATE changes the definition of an
aggregate function.
+
+ You must own the aggregate function to use ALTER AGGREGATE>;
+ except for ALTER AGGREGATE OWNER>, which may only be executed by
+ a superuser.
+ To change the schema of an aggregate function, you must also have
+ CREATE privilege on the new schema.
+
- newname
+ new_name
The new name of the aggregate function.
- newowner
+ new_owner
The new owner of the aggregate function.
- You must be a superuser to change an aggregate's owner.
+
+
+
+
+
+ new_schema
+
+ The new schema for the aggregate function.
integer to joe:
ALTER AGGREGATE myavg(integer) OWNER TO joe;
+
+
+
+ To move the aggregate function myavg for type
+ integer into schema myschema:
+ALTER AGGREGATE myavg(integer) SET SCHEMA myschema;
DROP CONSTRAINT constraint_name [ RESTRICT | CASCADE ]
ALTER DOMAIN name
OWNER TO new_owner
+ALTER DOMAIN name
+ SET SCHEMA new_schema
+
+
+ SET SCHEMA
+
+ This form changes the schema of the domain. Any constraints
+ associated with the domain are moved into the new schema as well.
+
+
+
You must own the domain to use ALTER DOMAIN>; except for
ALTER DOMAIN OWNER>, which may only be executed by a superuser.
+ To change a domain's schema, you must also have CREATE>
+ privilege on the new schema.
name
- The name (possibly schema-qualified) of an existing domain to
- alter.
+ The name (possibly schema-qualified) of an existing domain to
+ alter.
domain_constraint
- New domain constraint for the domain.
+ New domain constraint for the domain.
constraint_name
- Name of an existing constraint to drop.
+ Name of an existing constraint to drop.
Refuse to drop the constraint if there are any dependent
- objects. This is the default behavior.
+ objects. This is the default behavior.
new_owner
- The user name of the new owner of the domain.
+ The user name of the new owner of the domain.
+
+
+
+
+
+ new_schema
+
+ The new schema for the domain.
ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;
+
+ To move the domain into a different schema:
+ALTER DOMAIN zipcode SET SCHEMA customers;
+
+
Compatibility
- The ALTER DOMAIN statement is compatible with SQL:2003,
- except for the OWNER> variant, which is a
+
ALTER DOMAIN conforms with SQL:2003,
+ except for the OWNER> and SET SCHEMA> variants,
+
which are PostgreSQL extensions.
ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
action [, ... ] [ RESTRICT ]
ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
- RENAME TO newname
+ RENAME TO new_name
ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
- OWNER TO newowner
+ OWNER TO new_owner
+ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
+ SET SCHEMA new_schema
where action is one of:
ALTER FUNCTION changes the definition of a
function.
+
+ You must own the function to use ALTER FUNCTION>; except for
+ ALTER FUNCTION OWNER>, which may only be executed by a superuser.
+ To change a function's schema, you must also have CREATE>
+ privilege on the new schema.
+
- newname
+ new_name
The new name of the function.
- newowner
+ new_owner
- The new owner of the function. To change the owner of a
- function, you must be a superuser. Note that if the function is
+ The new owner of the function. Note that if the function is
marked SECURITY DEFINER, it will subsequently
execute as the new owner.
+
+ new_schema
+
+ The new schema for the function.
+
+
+
+
CALLED ON NULL INPUT
RETURNS NULL ON NULL INPUT
integer to joe:
ALTER FUNCTION sqrt(integer) OWNER TO joe;
+
+
+
+ To change the schema of the function sqrt for type
+ integer to maths:
+ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
FUNCTION> statement in the SQL standard. The standard allows more
properties of a function to be modified, but does not provide the
ability to rename a function, make a function a security definer,
- or change the owner or volatility of a function. The standard also
+ or change the owner, schema, or volatility of a function. The standard also
requires the RESTRICT> key word; it is optional in
ALTER SEQUENCE name [ INCREMENT [ BY ] increment ]
[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
[ RESTART [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
+ALTER SEQUENCE name SET SCHEMA new_schema
ALTER SEQUENCE changes the parameters of an existing
- sequence generator. Any parameter not specifically set in the
- ALTER SEQUENCE command retains its prior setting.
+ sequence generator. Any parameters not specifically set in the
+ ALTER SEQUENCE command retain their prior settings.
+
+
+ You must own the sequence to use ALTER SEQUENCE>.
+ To change a sequence's schema, you must also have CREATE>
+ privilege on the new schema.
+
+
+ new_schema
+
+ The new schema for the sequence.
+
+
+
values. They will use up all cached values prior to noticing the changed
sequence parameters. The current backend will be affected immediately.
+
+ Some variants of ALTER TABLE can be used with
+ sequences as well; for example, to rename a sequence use ALTER
+ TABLE RENAME.
+
Compatibility
-
ALTER SEQUENCE conforms with
SQL:2003.
+
ALTER SEQUENCE conforms with
SQL:2003,
+ except for the SET SCHEMA variant, which is a
RENAME [ COLUMN ] column TO new_column
ALTER TABLE name
RENAME TO new_name
+ALTER TABLE name
+ SET SCHEMA new_schema
where action is one of:
SET WITHOUT CLUSTER
SET WITHOUT OIDS
OWNER TO new_owner
- SET TABLESPACE tablespace_name
+ SET TABLESPACE new_tablespace
ADD COLUMN
- This form adds a new column to the table using the same syntax as
+ This form adds a new column to the table, using the same syntax as
.
+
+ SET SCHEMA
+
+ This form moves the table into another schema. Associated indexes,
+ constraints, and SERIAL-column sequences are moved as well.
+
+
+
+
- All the actions except RENAME can be combined into
+ All the actions except RENAME and SET SCHEMA>
+ can be combined into
a list of multiple alterations to apply in parallel. For example, it
is possible to add several columns and/or alter the type of several
columns in a single command. This is particularly useful with large
You must own the table to use ALTER TABLE>; except for
ALTER TABLE OWNER>, which may only be executed by a superuser.
+ To change the schema of a table, you must also have
+ CREATE privilege on the new schema.
- tablespace_name
+ new_tablespace
+
+ The name of the tablespace to which the table will be moved.
+
+
+
+
+
+ new_schema
- The tablespace name to which the table will be moved.
+ The name of the schema to which the table will be moved.
- To move a table to a different tablespace:
+ To move a table to a different tablespace:
ALTER TABLE distributors SET TABLESPACE fasttablespace;
+
+
+
+ To move a table to a different schema:
+ALTER TABLE myschema.distributors SET SCHEMA yourschema;
ALTER TYPE name OWNER TO new_owner
+ALTER TYPE name SET SCHEMA new_schema
ALTER TYPE changes the definition of an existing type.
- The only currently available capability is changing the owner of a type.
+ The only currently available capabilities are changing the owner and schema
+ of a type.
+
+ new_schema
+
+ The new schema for the type. To move a
+ type to a new schema, you must be the owner of the
+ type and have CREATE> privilege on the new schema.
+
+
+
+
ALTER TYPE email OWNER TO joe;
+
+ To change the schema of the user-defined type email
+ to customers:
+ALTER TYPE email SET SCHEMA customers;
+
+