When designing a service catalog or virtual server definition table in PostgreSQL, it is common to need a derived attribute that is automatically generated from several existing columns.
A practical example is a virtual server flavor code (SKU - Stock Keeping Unit) derived from these attributes:
- vserver_type – values such as
ECONOMY,STANDARD,PREMIUM - num_of_vcpu – number of vCPUs, for example 1 to 64
- capacity_of_vram – RAM size, for example 1 to 128
The requirement is to automatically generate a formatted code such as:
ECONOMY-04-016
In this format:
vserver_typeis converted to uppercasenum_of_vcpuis formatted to 2 digitscapacity_of_vramis formatted to 3 digits- the delimiter is a hyphen (
-)
