Creating object instances v14
To create an instance of an object type, you must first declare a variable of the object type and then initialize the declared object variable. The syntax for declaring an object variable is:
object is an identifier assigned to the object variable.
obj_type is the identifier of a previously defined object type.
After declaring the object variable, you must invoke a constructor method to initialize the object with values. Use the following syntax to invoke the constructor method:
obj_type is the identifier of the object type’s constructor method. The constructor method has the same name as the previously declared object type.
expr1, expr2, … are expressions that are type-compatible with the first attribute of the object type, the second attribute of the object type, and so on. If an attribute is of an object type, then the corresponding expression can be
NULL, an object initialization expression, or any expression that returns that object type.
This anonymous block declares and initializes a variable:
v_emp is declared with a previously defined object type named
EMP_OBJ_TYPE. The body of the block initializes the variable using the
You can include the
NEW keyword when creating a new instance of an object in the body of a block. The
NEW keyword invokes the object constructor whose signature matches the arguments provided.
This example declares two variables named
emp. The variables are both of
mgr object is initialized in the declaration, while the
emp object is initialized to
NULL in the declaration and assigned a value in the body.
In EDB Postgres Advanced Server, you can use the following alternate syntax in place of the constructor method.
ROW is an optional keyword if two or more terms are specified in the parenthesis-enclosed, comma-delimited list. If you specify only one term, then you must specify the