Object type specification syntax v17

The following is the syntax of the object type specification:

CREATE [ OR REPLACE ] TYPE <name>
  [ AUTHID { DEFINER | CURRENT_USER } ]
  { IS | AS } OBJECT
( { <attribute> { <datatype> | <objtype> | <collecttype> } }
    [, ...]
  [ <method_spec> ] [, ...]
  [ <constructor> ] [, ...]
) [ [ NOT ] { FINAL | INSTANTIABLE } ] ...;

Where method_spec is the following:

[ [ NOT ] { FINAL | INSTANTIABLE } ] ...
[ OVERRIDING ]
  <subprogram_spec>

Where subprogram_spec is the following:

{ MEMBER | STATIC }
{ PROCEDURE <proc_name>
    [ ( [  SELF [ IN | IN OUT ] <name> ]
        [, <parm1> [ IN | IN OUT | OUT ] <datatype1>
                   [ DEFAULT <value1> ] ]
        [, <parm2> [ IN | IN OUT | OUT ] <datatype2>
                   [ DEFAULT <value2> ]
        ] ...)
    ]
|
  FUNCTION <func_name>
    [ ( [  SELF [ IN | IN OUT ] <name> ]
        [, <parm1> [ IN | IN OUT | OUT ] <datatype1>
                   [ DEFAULT <value1> ] ]
        [, <parm2> [ IN | IN OUT | OUT ] <datatype2>
                   [ DEFAULT <value2> ]
        ] ...)
    ]
  RETURN <return_type>
}

Where constructor is the following:

CONSTRUCTOR FUNCTION <func_name>
  [ ( [ <parm1> [ IN | IN OUT | OUT ] <datatype1>
                 [ DEFAULT <value1> ] ]
      [, <parm2> [ IN | IN OUT | OUT ] <datatype2>
                 [ DEFAULT <value2> ]
      ] ...)
  ]
RETURN <return_type>;
Note
  • You can't use the OR REPLACE option to add, delete, or modify the attributes of an existing object type. Use the DROP TYPE command to first delete the existing object type. You can use the OR REPLACE option to add, delete, or modify the methods in an existing object type.

  • You can use the PostgreSQL form of the ALTER TYPE ALTER ATTRIBUTE command to change the data type of an attribute in an existing object type. However, the ALTER TYPE command can't add or delete attributes in the object type.

name is an identifier (optionally schema-qualified) assigned to the object type.

If you omit the AUTHID clause or specify DEFINER, the rights of the object type owner are used to determine access privileges to database objects. If you specify CURRENT_USER, the rights of the current user executing a method in the object determine access privileges.

Syntax

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 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 doesn't currently support creating subtypes.

Following the closing parenthesis of the CREATE TYPE definition, [ NOT ] INSTANTIABLE specifies whether an object instance of this object type can be created. 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 defined. If NOT INSTANTIABLE is specified, then you must specify NOT FINAL as well. If any method in the object type contains the NOT INSTANTIABLE qualifier, then the object type must be defined with NOT INSTANTIABLE and NOT FINAL.

Note

Even though specifying NOT INSTANTIABLE is accepted in the CREATE TYPE command, SPL doesn't currently support creating subtypes.

method_spec

method_spec denotes the specification of a member method or static method.

Before defining a method, use [ NOT ] FINAL to specify whether the method can be overridden in a subtype. NOT FINAL is the default, meaning the method can be overridden in a subtype.

Before defining 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 with the same return type (if the method is a function) as defined in the supertype.

Before defining a method, use [ NOT ] INSTANTIABLE to specify whether the object type definition provides an implementation for the method. If you specify INSTANTIABLE, then the CREATE TYPE BODY command for the object type must specify the implementation of the method. If you specify NOT INSTANTIABLE, 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 must specify NOT INSTANTIABLE and NOT FINAL following the closing parenthesis of the object type specification. The default is INSTANTIABLE.

subprogram_spec

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 isn't invoked with respect to any object instance.

proc_name is an identifier of a procedure. If you specify the SELF parameter, 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. The default is IN. value1, value2, … are default values that you can specify for IN parameters.

CONSTRUCTOR

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. The default is IN. value1, value2, … are default values that you can specify for IN parameters. return_type is the data type of the value the function returns.

Note the following about an object type specification:

  • There must be at least one attribute defined in the object type.

  • There can be zero, one, or more methods defined in the object type.

  • A static method can't be overridden. You can't specify OVERRIDING and STATIC together in method_spec.

  • A static method must be instantiable. You can't specify NOT INSTANTIABLE and STATIC together in method_spec.