Defining PostgreSQL User Defined Types

The following properties are applicable to a PostgreSQL User Defined Type object.

Tab

Section

Property

Description

Additional Properties

 

 

Name

Specifies the name of the user-defined type

 

 

 

Schema

Specifies the schema of the database to which the user-defined type belongs

Select the schema from the drop-down list or click New icon in property editors to create a new object to create a new object

 

 

Generate

Specifies whether a SQL statement is generated during forward engineering

 

General

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Type Options

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

UDT Type

Specifies the user-defined type

Base Type: Specifies that base types are fundamental scalar data types implemented at a low level, typically in a language like C. These base types serve as the building blocks for more complex data structures.

Ensure that you have superuser access to create a new base type.

Enumerated Type: Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to the enum types supported in several programming languages. An example of an enum type might be the days of the week or a set of status values for a piece of data.

Range Type: Allows you to represent a range of values for a specific underlying data type. These ranges are useful for scenarios where you need to express intervals or spans of values.

Composite Type: Allows you to define custom data structures with multiple fields. These fields can be any built-in or user-defined types, including other composite types.

Domain Type: Domain type builds upon an existing underlying type. It allows you to create a custom type with specific constraints.

Pseudo Type: The PostgreSQL type system contains several special-purpose entries collectively called pseudo-types. A pseudo-type cannot be used as a column data type but can be used to declare a function's argument or result type. Each of the available pseudo-types is useful when a function's behavior does not correspond to simply taking or returning a value of a specific SQL data type.

Input Function

Specifies the name of a function that converts data from the type's external textual form to its internal form

Available only when UTD type is set to Base Type.

Output Function

Specifies the name of a function that converts data from the type's internal form to its external textual form

Receive Function

Specifies the name of a function that converts data from the type's external binary form to its internal form. Select a function from the drop-down list or click New icon in property editors to create a new object to create a new one.

Send Function

Specifies the name of a function that converts data from the type's internal form to its external binary form. Select a function from the drop-down list or click New icon in property editors to create a new object to create a new one.

Modifier Input Function

Specifies the name of a function that converts an array of modifier(s) for the type into an internal form. Select a function from the drop-down list or click New icon in property editors to create a new object to create a new one.

Modifier Output Function

Specifies the name of a function that converts the internal form of the type's modifier(s) to external textual form. Select a function from the drop-down list or click New icon in property editors to create a new object to create a new one.

Analyze Function

Specifies the name of a function that performs statistical analysis for the data type. Select a function from the drop-down list or click New icon in property editors to create a new object to create a new one.

Subscript Function

Enables the subscripting of data types in SQL commands

Internal_Length

Specifies a numeric constant that indicates the length in bytes of the new type's internal representation. The default assumption is that it is variable-length.

Passed By Value

Indicates that values of the data type are passed by value, rather than by reference

Alignment

Specifies the storage alignment requirement of the data type. If specified, it must be char, int2, int4, or double; the default is int4. Select a storage alignment from the drop-down list.

Available only when UTD type is set to Base Type.

Int4: Represents a 4-byte signed integer and allows for a wide range of values. It stores numbers in the range of -2,147,483,648 to +2,147,483,6471.

Char: It represents a single character (such as a letter, digit, or symbol) within a text or string. It occupies 1 byte of memory and stores a numeric value corresponding to the character’s ASCII code.

Int2: Represents a signed two-byte integer, allowing for values from -32,768 to 32,7671.

Double: Store floating-point numbers with double precision. It occupies 4 bytes (32 bits) of memory and provides approximately seven decimal digits of precision.

Storage Strategy

Specifies the storage strategy for the data type. If specified, it must be plain, external, extended, or main; the default is plain. Select a storage strategy from the drop-down list.

Available only when UTD type is set to Base Type.

Plain: Specifies that data of the type will always be stored in-line and not compressed

External: Allows the value to be moved out of the main table, but the system will not try to compress it.

Extended: Specifies that the system will first try to compress a long data value and will move the value out of the main table row if it's still too long

Main: Allows compression but discourages moving the value out of the main table

Like Type

Specifies the name of an existing data type so that the new type will have the same representation. Select a data type from the drop-down list or click New icon in property editors to create a new object to create a new one

Available only when UTD type is set to Base Type.

Category

Specifies the category code (a single ASCII character) for the type. Select a category code from the drop-down list.

Available only when UTD type is set to Base Type.

Array Types: Allows you to store a collection of values within a single database column. Arrays can hold elements of any data type, including numbers, strings, or even other arrays.

Boolean Types: Specifies the state of true or false.

Composite Types: Signifies the structure of a row or record as a list of file names and data types.

Date Type: Used to store date values. It represents a date in the format of YYYY-MM-DD, where:

  • YYYY represents the year with four digits.

  • MM represents the month with two digits (01 for January, 02 for February, and so on).

  • DD represents the day of the month with two digits (01 through 31).

Enum Types: Allows you to define a set of possible values for a column.

Geometric Types: Represent two-dimensional spatial objects. The most fundamental type, the point, forms the basis for all other types.

Network address types: Provides data types to store Mac Address, IPv4, and IPv6, as we can see in the table below. It enhances these types other than plain text types to contain network addresses as these offer input error checking and particular functions and operators.

Numeric Types: Used to specify the numeric data in the table. It contains the following:

  • four- and eight-byte floating-point numbers

  • two-, four-, and eight-byte integers

  • Selectable-precision decimals.

Pseudo Types: These are used to contain many special-purpose entries. They are also used to declare a result type or the function's argument but are not compatible for use as a column data type.

Range types: Displays a range of values of some element types, known as the range's subtype. It also signifies several elements of values in a single range value. We can also create our range types with this.

String types: Keeps the character of infinite length. The text data type can hold a string with a maximum length of 65,535 bytes.

Timespan types: Handles time values. It requires 8 bytes of storage and can be precise up to 6 digits. It can range from 00:00:00 to 24:00:00.

User Defined types: Allows you to define your custom data types, known as user-defined types (UDTs). This allows you to create data structures that suit your needs, encapsulate complex logic, and enhance data integrity.

Bit String types: Stores fixed-length or variable-length bit strings. Bit strings are sequences of binary digits (0 and 1). PostgreSQL provides two types of bit strings: BIT and BIT VARYING.

unknown type: The system uses it as a special placeholder data type to handle string literals that are not explicitly cast to any specific data type.

Is_Preferred

Specifies whether the type is a preferred type within its type category. The default is false

Available only when UTD type is set to Base Type.

Type Default

Specifies the default value for the data type. If omitted, the default is null.

Element

Indicates that the type being created is an array and specifies the type of the array elements. Select a user-defined type from the drop-down list or click New icon in property editors to create a new object to create a new one

Delimiter

Specifies the delimiter character to use between values in arrays of this type

Collatable

Specifies whether the type's operations can use collation information. The default is false

Enumerated Values

Specifies the value for Enumerated Type in the form of a static, ordered set of values

Available only when UTD type is set to Enumerated Type.

SubType Value

Indicates a range of values of the element type

Available only when UTD type is set to Range Type.

Subtype Operator Class

Specifies the name of a b-tree operator class for the subtype

Collation

Specifies the name of an existing collation associated with a composite or range column. Select a collation from the drop-down list or click New icon in property editors to create a new object to create a new one

Canonical Function

Specifies the canonicalization function for the range type

Subtype Diff Function

Specifies the name of a difference function for the subtype

Multirange Type Name

Specifies the name of the corresponding multirange type

Columns

UDT Column

Name

Specifies the name of the user-defined type's attribute

 

Physical Data Type

Specifies the physical data type for the selected column

 

Collation

Specifies a collation to assign to the attribute, which must be of a collatable data type

 

  1. (Optional) Click the Comment tab and enter any comments you want to associate with the object.
  2. (Optional) Click the UDP tab to work with user-defined properties for the object.
  3. (Optional) Click the Notes tab to view and edit user notes.
  4. (Optional) Click the Extended Notes tab to view or edit user notes.
  5. Click Close.

    The user-defined type is defined, and the PostgreSQL User Defined Type Editor closes.

For more information, refer to PostgreSQL documentation.