Object Type Specification Syntax v13
The following is the syntax of the object type specification:
where method_spec
is the following:
where subprogram_spec
is the following:
where constructor
is the following:
Note
The
OR REPLACE
option cannot be currently used to add, delete, or modify the attributes of an existing object type. Use theDROP TYPE
command to first delete the existing object type. TheOR REPLACE
option can be used to add, delete, or modify the methods in an existing object type.The PostgreSQL form of the
ALTER TYPE ALTER ATTRIBUTE
command can be used to change the data type of an attribute in an existing object type. However, theALTER TYPE
command cannot add or delete attributes in the object type.
name
is an identifier (optionally schema-qualified) assigned to the object type.
If the AUTHID
clause is omitted or DEFINER
is specified, the rights of the object type owner are used to determine access privileges to database objects. If CURRENT_USER
is specified, the rights of the current user executing a method in the object are used to determine access privileges.
attribute
is an identifier assigned to an attribute of the object type.
datatype
is a base data type.
objtype
is a previously defined object type.
collecttype
is a previously defined collection type.
Following the closing parenthesis of the CREATE TYPE
definition, [ NOT ] FINAL
specifies whether or not a subtype can be derived from this object type. FINAL
, which is the default, means that no subtypes can be derived from this object type. Specify NOT FINAL
if you want to allow subtypes to be defined under this object type.
Note
Even though the specification of NOT FINAL
is accepted in the CREATE TYPE
command, SPL does not currently support the creation of subtypes.
Following the closing parenthesis of the CREATE TYPE
definition, [ NOT ] INSTANTIABLE
specifies whether or not an object instance can be created of this object type. INSTANTIABLE
, which is the default, means that an instance of this object type can be created. Specify NOT INSTANTIABLE
if this object type is to be used only as a parent “template” from which other specialized subtypes are to be defined. If NOT INSTANTIABLE
is specified, then NOT FINAL
must be specified as well. If any method in the object type contains the NOT INSTANTIABLE
qualifier, then the object type, itself, must be defined with NOT INSTANTIABLE
and NOT FINAL
.
Note
Even though the specification of NOT INSTANTIABLE
is accepted in the CREATE TYPE
command, SPL does not currently support the creation of subtypes.
method_spec
denotes the specification of a member method or static method.
Prior to the definition of a method, [ NOT ] FINAL
specifies whether or not the method can be overridden in a subtype. NOT FINAL
is the default meaning the method can be overridden in a subtype.
Prior to the definition of a method specify OVERRIDING
if the method overrides an identically named method in a supertype. The overriding method must have the same number of identically named method parameters with the same data types and parameter modes, in the same order, and the same return type (if the method is a function) as defined in the supertype.
Prior to the definition of a method, [ NOT ] INSTANTIABLE
specifies whether or not the object type definition provides an implementation for the method. If INSTANTIABLE
is specified, then the CREATE TYPE BODY
command for the object type must specify the implementation of the method. If NOT INSTANTIABLE
is specified, then the CREATE TYPE BODY
command for the object type must not contain the implementation of the method. In this latter case, it is assumed a subtype contains the implementation of the method, overriding the method in this object type. If there are any NOT INSTANTIABLE
methods in the object type, then the object type definition itself, must specify NOT INSTANTIABLE
and NOT FINAL
following the closing parenthesis of the object type specification. The default is INSTANTIABLE
.
subprogram_spec
denotes the specification of a procedure or function and begins with the specification of either MEMBER
or STATIC
. A member subprogram must be invoked with respect to a particular object instance while a static subprogram is not invoked with respect to any object instance.
proc_name
is an identifier of a procedure. If the SELF
parameter is specified, name
is the object type name given in the CREATE TYPE
command. If specified, parm1, parm2, …
are the formal parameters of the procedure. datatype1, datatype2, …
are the data types of parm1, parm2, …
respectively. IN, IN OUT
, and OUT
are the possible parameter modes for each formal parameter. If none are specified, the default is IN
. value1, value2, …
are default values that may be specified for IN
parameters.
Include the CONSTRUCTOR FUNCTION
keyword and function definition to define a constructor function.
func_name
is an identifier of a function. If specified, parm1, parm2, …
are the formal parameters of the function. datatype1, datatype2, …
are the data types of parm1, parm2, …
respectively. IN, IN OUT
, and OUT
are the possible parameter modes for each formal parameter. If none are specified, the default is IN
. value1, value2, …
are default values that may be specified for IN
parameters. return_type
is the data type of the value the function returns.
The following points should be noted about an object type specification:
There must be at least one attribute defined in the object type.
There may be none, one, or more methods defined in the object type.
A static method cannot be overridden (
OVERRIDING
andSTATIC
cannot be specified together inmethod_spec
).A static method must be instantiable (
NOT INSTANTIABLE
andSTATIC
cannot be specified together inmethod_spec
).