The SQL CREATE TYPE command creates a user-defined object type, which is stored in the EDB Postgres Advanced Server database.
You can then reference these user-defined types in SPL procedures, SPL functions, and .NET programs.
The basic object type is created with the CREATE TYPE AS OBJECT command with optional use of the CREATE TYPE BODY command.
Using an object type
To use an object type, you must first create the object type in the EDB Postgres Advanced Server database. Object type addr_object_type defines the attributes of an address:
Object type emp_obj_typ defines the attributes of an employee. One of these attributes is object type ADDR_OBJECT_TYPE, as previously described. The object type body contains a method that displays the employee information:
The following listing is a complete .NET program that uses these user-defined object types:
The following .NET types are defined to map to the types in EDB Postgres Advanced Server:
A call to EDBConnection.GlobalTypeMapper.MapComposite maps the .NET type to the EDB Postgres Advanced Server types:
A call to EDBCommandBuilder.DeriveParameters() gets parameter information for a stored procedure. This allows you to just set the parameter values and call the stored procedure:
The value of the parameter is set by creating an object of the .NET type and assigning it to the Value property of the parameter:
A call to cmd.ExecuteNonQuery() executes the call to the display_emp() method: